禁用Datepicker中的特定日期 [英] Disable Specific Dates in Datepicker
问题描述
我正在尝试从我的在线预订脚本中的datepicker中禁用特定日期(多个金额)。我已经浏览了大量的Google搜索解决方案,但没有一个似乎与我的脚本一起工作。
I am trying to disable specific dates (multiple amounts) from datepicker in my online booking script. I have looked through handfuls of Google searches for a solution but none of them seem to work with my script.
编辑:当我说它不适用于这个脚本我的意思是说所有的日期都会被禁用或者日期戳不显示。
When I say it doesn't work with this script, I mean either all of the dates become disabled or the datepicker doesn't appear.
我们以前想禁用星期天,BG101帮助我们完成了(谢谢)
We previously wanted to disable Sundays and BG101 helped us accomplish (thank you) this with
$this.datepicker($.extend(dOpts, {
beforeShowDay: function(date) {
return [(date.getDay() != 0), '']; // 0 => Sunday
}
}));
任何帮助和指导将深深感激。这变成一个8小时的项目:(
Any help and guidance would be deeply appreciated.This turned into a 8 hour project :(
这是我的脚本: http://pastebin.com/xDFxXUeJ
推荐答案
Sorav Garg的答案是正确的排除具体日期,虽然你需要组合星期天也不包括: -
Sorav Garg's answer is correct for excluding specific days, though you will need to combined the exclude of sunday also:-
下面是一个排除下周的例子: -
Here is an example of excluding all of next week:-
var exclude = ["16-11-2015", "17-11-2015", "18-11-2015", "19-11-2015", "20-11-2015", "21-11-2015"]
$('#calendar').datepicker({
beforeShowDay: function(date) {
var day = jQuery.datepicker.formatDate('dd-mm-yy', date);
return [!~$.inArray(day, exclude) && (date.getDay() != 0)];
}
});
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/redmond/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<input id="calendar" />
这篇关于禁用Datepicker中的特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!