我目前只有星期五的日期选择器。我想继续只允许星期五,但修改此代码以禁用一个日期:12-31-2010(恰好是星期五)。我已经看到了关于如何disable dates的代码示例,但我不知道如何在不破坏它的情况下将此功能添加到我当前的代码中。
星期五代码:
//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()? [true,''] : [false,'']);}
});
});
答案 0 :(得分:0)
你可以试试这个:
//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,'']);}
});
});
答案 1 :(得分:0)
如果要禁用特定日期,则必须以这种方式在显示日期之前更改功能
function(d) {
var disabledDate= new Date(2010,12,31);
return [(d.getDay() == 5 && d != disabledDate), ''];
}
答案 2 :(得分:0)
对不起我的错误答案 这是正确的
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
});
});
我尝试,我确定它是正确的