开发者

jQuery Datepicker: Only Select Fridays AND Disable One Specific Date

开发者 https://www.devze.com 2023-01-25 06:41 出处:网络
I currently have datepicker only allowing Fridays.I would like to continue to only allow Fridays, but modify this code to disable one date: 12-31-2010 (which happens to be Friday).I have seen code exa

I currently have datepicker only allowing Fridays. I would like to continue to only allow Fridays, but modify this code to disable one date: 12-31-2010 (which happens to be Friday). I have seen code examples on how to disable dates, but I do not know how to add this functionality into my current code without breaking it.

Friday Only Code:

//Get todays date
var m_names = new Array("January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December");

var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();

//Function for datepicker
$(function () { 
        $('#datepicker').datepicker({ 
        minDate: (new Date(d)),
        beforeShowDay: function(d)开发者_Python百科 {return ( 5==d.getDay()? [true,''] : [false,'']);} 
    }); 
});


I'm sorry for my wrong answer This is correct

function enableFirday(d) { {
    var disabledDate= new Date(2010,11,31);

    var curr_date = d.getDate();
    var curr_month = d.getMonth();
    var curr_year = d.getFullYear();

    var dDate = new Date(curr_year, curr_month, curr_date);
    return [(d.getDay() == 5 && dDate.toString() != disabledDate.toString()), ''];
 }

$(document).ready(function() {
      $("#datepicker9").datepicker({
    dateFormat: 'dd-mm-yy',
    minDate: 1,
    beforeShowDay: enableFirday
});

});

I try and I'm sure it's correct


You could try this:

//Get todays date
var m_names = new Array("January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December");

var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();

//Function for datepicker
$(function () { 
        $('#datepicker').datepicker({ 
        minDate: (new Date(d)),
        beforeShowDay: function(d) {return ( 5==d.getDay() || (((d.getMonth()+1) + '-' + d.getDate() + '-' + d.getFullYear()) == '12-31-2010'))? [true,''] : [false,'']);} 
    }); 
});


If you want disable a specifical date you have to change the function beforeShowDay in this way

 function(d) {
    var disabledDate= new Date(2010,12,31);
    return [(d.getDay() == 5 && d != disabledDate), ''];
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消