简体   繁体   English

在 Datepicker 中禁用特定日期

[英]Disable Specific Dates in Datepicker

I am trying to disable specific dates (multiple amounts) from datepicker in my online booking script.我正在尝试从我的在线预订脚本中的 datepicker 禁用特定日期(多个金额)。 I have looked through handfuls of Google searches for a solution but none of them seem to work with my script.我浏览了一些 Google 搜索以寻找解决方案,但似乎没有一个适用于我的脚本。

Edit: 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.编辑:当我说它不适用于此脚本时,我的意思是所有日期都被禁用或日期选择器不出现。

We previously wanted to disable Sundays and BG101 helped us accomplish (thank you) this with我们以前想禁用星期日,BG101 帮助我们完成了(谢谢)

$this.datepicker($.extend(dOpts, {
    beforeShowDay: function(date) {
        return [(date.getDay() != 0), '']; // 0 => Sunday
    }
}));

Any help and guidance would be deeply appreciated.This turned into a 8 hour project :(任何帮助和指导将不胜感激。这变成了一个 8 小时的项目:(

Here is my script: http://pastebin.com/xDFxXUeJ这是我的脚本: http : //pastebin.com/xDFxXUeJ

Sorav Garg's answer is correct for excluding specific days, though you will need to combined the exclude of sunday also:- Sorav Garg 的答案对于排除特定日期是正确的,但您还需要结合星期天的排除:-

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" />

@mark please try this it will work -- @mark 请试试这个它会工作-

for bootstrap datepicker --

http://jsfiddle.net/Lr3taznx/35/ http://jsfiddle.net/Lr3taznx/35/

for jquery datepicker --

http://jsfiddle.net/CxNNh/2568/ http://jsfiddle.net/CxNNh/2568/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM