Javascript 在jQuery Datepicker中禁用天数取决于MVC模型中的其他属性
我想在Javascript 在jQuery Datepicker中禁用天数取决于MVC模型中的其他属性,javascript,jquery,asp.net-mvc,razor,jquery-ui-datepicker,Javascript,Jquery,Asp.net Mvc,Razor,Jquery Ui Datepicker,我想在jQuery UI DatePicker中禁用一周中的特定天数,具体取决于@razor view中提交的模型中的值是true还是false 我每个工作日都有一本书。如果构建了一个值,那么datepickern中的日期将可用,但如果为false,则该日期将被禁用 我从不同的角度看了看,但这些选择都不适合我。 这是我的密码: $('#txtStartDate').datepicker({ defaultDate: '+1w', numberOfMonths: 1, sh
jQuery UI DatePicker
中禁用一周中的特定天数,具体取决于@razor view中提交的模型中的值是true还是false
我每个工作日都有一本书。如果构建了一个值,那么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未捕获类型错误:无法读取属性“0”
“未定义的”
尽管如此,我已经环顾了这里提出的解决方案,但它可能不起作用。此解决方案基于以下建议:
提前谢谢。我在这里检查了您的代码 当未返回day对象时(当未返回day对象时),会出现错误 进入任何if条件)。你不能不回来 如果不满足任何条件,最好返回false
我在这里检查了你的代码 当未返回day对象时(当未返回day对象时),会出现错误 进入任何if条件)。你不能不回来 如果不满足任何条件,最好返回false
Acutally
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,“,”],其中禁用Acutally的标志为false,在ShowDay之前
应返回一个数组。它的文件就是这么说的
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,否则返回一个数组[flag,“,”],其中禁用的标志为false
,谢谢您的回答。当我试图在不满足任何条件的情况下返回false时,它会禁用所有天,即使某些天应该启用?您也需要返回true。当你的病情好转时,谢谢你的回答。当我试图在不满足任何条件的情况下返回false时,它会禁用所有天,即使某些天应该启用?您也需要返回true。当你的条件满足时