Dan*_*ite 80 jquery-ui jquery-ui-datepicker
我一直在努力寻找解决我的Jquery ui datepicker问题的解决方案而且我没有运气.这就是我想要做的......
我有一个应用程序,我正在做一些复杂的PHP来返回一个JSON数组的日期,我希望BLOCKED从Jquery UI Datepicker中获取.我正在返回这个数组:
["2013-03-14","2013-03-15","2013-03-16"]
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法可以简单地说:从datepicker中阻止这些日期?
我已经阅读了UI文档,但我没有看到任何对我有帮助的内容.有人有主意吗?
Aru*_*hny 188
您可以使用beforeShowDay来执行此操作
以下示例禁用2013年3月14日至2013年3月16日的日期
var array = ["2013-03-14","2013-03-15","2013-03-16"]
$('input').datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ array.indexOf(string) == -1 ]
}
});
Run Code Online (Sandbox Code Playgroud)
演示:小提琴
小智 19
IE 8没有indexOf函数,所以我使用了jQuery inArray.
$('input').datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [$.inArray(string, array) == -1];
}
});
Run Code Online (Sandbox Code Playgroud)
小智 9
如果你想阻止星期日(或其他日子)以及日期数组,我使用这段代码:
jQuery(function($){
var disabledDays = [
"27-4-2016", "25-12-2016", "26-12-2016",
"4-4-2017", "5-4-2017", "6-4-2017", "6-4-2016", "7-4-2017", "8-4-2017", "9-4-2017"
];
//replace these with the id's of your datepickers
$("#id-of-first-datepicker,#id-of-second-datepicker").datepicker({
beforeShowDay: function(date){
var day = date.getDay();
var string = jQuery.datepicker.formatDate('d-m-yy', date);
var isDisabled = ($.inArray(string, disabledDays) != -1);
//day != 0 disables all Sundays
return [day != 0 && !isDisabled];
}
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
129234 次 |
| 最近记录: |