如何在jquery datepicker中禁用周日? (仅限周末和特定节日) [英] How to disable week days in jquery datepicker? (Enable only weekends and two specific festive days)
问题描述
我很生气尝试这个...
如何在jquery datepicker中禁用周日? (只启用周末和两个特定的节日)
I´m getting mad trying this... How to disable week days in jquery datepicker? (Enable only weekends and two specific festive days)
我尝试了很多o代码显示在这里,但没有为我工作...
I tryed a lot o codes showed here and away but doesn´t work for me...
如何禁用年度下拉?只需要这个年份
And how to disable year dropdown? Want only this current year
有人能帮我吗?
提前感谢!
Can anybody help me?? Thanks in advance!
推荐答案
这是如何禁用周末仅在周末,并添加自定义日期(您的两个具体节日)。我不知道你的节日是什么,所以我简单地在下面的例子中使用1/15/2014和1/16/2014。
Here is how to disable weekdays leaving only weekends AND add custom days (your two specific festive days). I don't know what your festive days are so I simply used 1/15/2014 and 1/16/2014 in the example below.
var availableDates = ["15-1-2014","16-1-2014"];
$(function()
{
$('#txtDate').datepicker({ beforeShowDay:
function(dt)
{
return [dt.getDay() == 0 || dt.getDay() == 6 || available(dt), "" ];
}
, changeMonth: true, changeYear: false});
});
function available(date) {
dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
if ($.inArray(dmy, availableDates) != -1) {
return true;
} else {
return false;
}
}
更新:我删除了年下拉列表
Update: i removed the year dropdown as well now
更新2:所以以前所有尝试都没有工作的原因是你有一个脚本(包括你的html文件的底部),它正在应用datepicker初始化代码到每个元素的class =datepicker
Update 2: So the reason all your previous attempts were not working is that you have a script you're including (bottom of your html file) that is applying the datepicker initialization code to every element that has class="datepicker"
这是覆盖你在文件顶部尝试的任何东西。从您的html文件中删除以下行:
This is overriding anything you try at the top of your file. Remove the following line from your html file:
<script type='text/javascript' src='http://entrestaciones.es/wp-content/plugins/gravityforms/js/datepicker.js?ver=1.8.1'></script>
或从不想自动初始化的输入元素中删除`class =datepicker
or remove the `class="datepicker" from the input elements you dont want auto initialized
这篇关于如何在jquery datepicker中禁用周日? (仅限周末和特定节日)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!