[英]Disable Friday and Saturday In Datepicker
I am trying to edit the beforeShowDay function in jquery.ui.datepicker. 我正在尝试在jquery.ui.datepicker中编辑beforeShowDay函数。 This is the original beforeShowDay lines in datepicker I'm trying to replace:
这是我要替换的datepicker中的原始 beforeShowDay行:
beforeShowDay: null, // Function that takes a date and returns an array with
// [0] = true if selectable, false if not, [1] = custom CSS class
name(s) or '',
// [2] = cell title (optional), e.g. $.datepicker.noWeekends
I have searched around trying to find the correct code to replace it with with no luck. 我四处搜寻,试图找到正确的代码来代替它,但没有运气。 I found this fiddle;
我发现了这个小提琴; disable 1 day in datepicker
在日期选择器中禁用1天
I have edited this fiddle and succeeded in disabling Friday and Saturday with the following code: 我已经编辑了这个小提琴,并使用以下代码成功禁用了星期五和星期六:
$("#datepicker").datepicker({
beforeShowDay: function(date) {
return [date.getDay() == 0 || date.getDay() == 1 || date.getDay() == 2 || date.getDay() == 3 || date.getDay() == 4 ] ;
}
});
However when I copy and paste this into jquery.ui.datepicker the calendar does not function and I'm getting console errors (Uncaught SyntaxError: Unexpected token). 但是,当我将其复制并粘贴到jquery.ui.datepicker中时,日历无法正常工作,并且出现控制台错误(未捕获的SyntaxError:意外的令牌)。
What I'm doing is replacing the original beforeShowDate with the following: 我正在用以下内容替换原始的 beforeShowDate:
beforeShowDay: function(date) { return [date.getDay() == 0 || date.getDay() == 1 || date.getDay() == 2 || date.getDay() == 3 || date.getDay() == 4 ] ; }
Can anyone advise what I'm doing wrong and how I can get this to function correctly? 谁能告诉我我做错了什么以及如何使它正常运行?
daysOfWeekDisabled
daysOfWeekDisabled
Days of the week that should be disabled.
应该在星期几禁用。 Values are 0 (Sunday) to 6 (Saturday).
值是0(星期日)到6(星期六)。 Multiple values should be comma-separated.
多个值应以逗号分隔。 Example: disable weekends: '06' or '0,6' or [0,6].
示例:禁用周末:“ 06”或“ 0,6”或[0,6]。
Use daysOfWeekDisabled
for this 为此使用
daysOfWeekDisabled
$('#datepicker').datepicker({
daysOfWeekDisabled: [5,6]
});
Edit 编辑
I did mistake in reading and post above answer about bootstarp datepicker. 我在阅读和发布上述有关bootstarp datepicker的答案时犯了错误。
For Jquery UI Datepicker try this 对于Jquery UI Datepicker,请尝试以下操作
beforeShowDay: function(d) {
return [!(d.getDay()==0||d.getDay()==6)]
}
You should not edit the jQuery UI plugin directly 您不应该直接编辑jQuery UI插件
If you really want then you have to paste this code replacing null. 如果确实需要,则必须粘贴此代码以替换null。 but it is not recommended .
但是不建议这样做 。
function(date) {
var show = true;
if(date.getDay()==6||date.getDay()==0) show=false;
return [show];
},//don't forget comma after the function
Right way to do is to pass the function while configuring the jquery ui date-picker inside your own js file. 正确的方法是在自己的js文件中配置jQuery ui date-picker时传递函数。
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var show = true;
if(date.getDay()==6||date.getDay()==0) show=false
return [show];
}
});
You can try this, 你可以试试看
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var day = date.getDay();
return [(day != 5 && day != 6), ''];
}
});
http://jsfiddle.net/nWAnz/238/ http://jsfiddle.net/nWAnz/238/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.