从html datepicker jquery中禁用特定日期

嘿家伙我想在我的网页上设置一个日期选择器,并禁用它的一些日期,所以它无法显示
这是代码:

    Untitled Document     /** Days to be disabled as an array */ var disableddates = ["20-5-2015", "12-11-2014", "12-25-2014", "12-20-2014"]; function DisableSpecificDates(date) { var m = date.getMonth(); var d = date.getDate(); var y = date.getFullYear(); // First convert the date in to the mm-dd-yyyy format // Take note that we will increment the month count by 1 var currentdate = (m + 1) + '-' + d + '-' + y; // We will now check if the date belongs to disableddates array for (var i = 0; i < disableddates.length; i++) { // Now check if the current date is in disabled dates array. if ($.inArray(currentdate, disableddates) != -1) { return [false]; } } } $(function () { $("#date").datepicker({ beforeShowDay: DisableSpecificDates }); });       

但由于某种原因它不起作用…日期选择器甚至没有显示可以有人帮助

试试这个,运行下面的代码。 第一个日期我在当天添加了0,以便它与比较中的格式匹配。

 /** Days to be disabled as an array */ var disableddates = ["20-05-2015", "12-11-2014", "12-25-2014", "12-20-2014"]; function DisableSpecificDates(date) { var string = jQuery.datepicker.formatDate('dd-mm-yy', date); return [disableddates.indexOf(string) == -1]; } /* var m = date.getMonth(); var d = date.getDate(); var y = date.getFullYear(); // First convert the date in to the mm-dd-yyyy format // Take note that we will increment the month count by 1 var currentdate = (m + 1) + '-' + d + '-' + y ; // We will now check if the date belongs to disableddates array for (var i = 0; i < disableddates.length; i++) { // Now check if the current date is in disabled dates array. if ($.inArray(currentdate, disableddates) != -1 ) { return [false]; } } }*/ $(function() { $("#date").datepicker({ beforeShowDay: DisableSpecificDates }); }); 
     Untitled Document         

这个答案是基于托马斯的回答,这里我在PrepareDate添加了noweekendsfunction到DisableSpecificDates函数,在beforeShowDay使用如: beforeShowDay:PrepareDate

 function DisableSpecificDates(date) { var string = jQuery.datepicker.formatDate('dd-mm-yy', date); return [disableddates.indexOf(string) == -1]; } function PrepareDate(date){ if ($.datepicker.noWeekends(date)[0]) { return DisableSpecificDates(date); } else { return $.datepicker.noWeekends(date); } } 

本周残疾人士日