我希望在jQuery UI DatePicker中禁用一周中的特定天数,这取决于在@剃须刀视图中提交的模型中的值是真是假。
我每个工作日都有一次嘘声。如果值是这样构造的,那么日期将在datepickern中可用,但如果为false,则该日期将被禁用。
我从不同的角度看了看,但这些选择对我都没有用。这是我的代码:
$('#txtStartDate').datepicker({
defaultDate: '+1w',
numberOfMonths: 1,
showAnim: 'slide',
changeMonth: true,
changeYear: true,
showWeek: true,
dateFormat: "yy-mm-dd",
minDate: new Date(hidStartDate),
beforeShowDay: function(date) {
var day = date.getDay();
if (day == 1 && $('#hidMonday').val() == "True") {
return day;
}
if (day == 2 && $('#hidTuesday').val() == "True") {
return day;
}
if (day == 3 && $('#hidWednesday').val() == "True") {
return day;
}
if (day == 4 && $('#hidThursday').val() == "True") {
return day;
}
if (day == 5 && $('#hidFriday').val() == "True") {
return day;
}
},
});
$('#txtStartDate').css('clip', 'auto');一旦它在日历中经历了大约5-6天,我就会在控制台中得到以下错误
JQuery-ui.js: 9742未定义的TypeError :无法读取未定义的属性'0‘
尽管如此,我已经看过这里提出的解决办法,但可能行不通。这一解决办法的基础是以下建议:
提前谢谢。
发布于 2016-06-23 06:40:27
我在这个小提琴中检查了您的代码
if (day == 1 && $('#hidMonday').val() == "True") {
return day;
}
if (day == 2 && $('#hidTuesday').val() == "True") {
return day;
}当不返回day (当它没有进入任何if条件)时,就会出现错误。如果不满足任何条件,就不能简单地不返回更好的返回false。
发布于 2016-06-23 07:03:01
实际上,beforeShowday应该返回一个数组。这就是它的文件上写的
beforeShowDay
Type: Function( Date date )
Default: null
A function that takes a date as a parameter and must return an array with:
[0]: true/false indicating whether or not this date is selectable
[1]: a CSS class name to add to the date's cell or "" for the default presentation
[2]: an optional popup tooltip for this date*默认情况下您可以发送null,否则返回一个array[flag,"",""] where flag is false for disabling
https://stackoverflow.com/questions/37983363
复制相似问题