假日和周末的MVC Datepicker
日期选择器
var array = ["2015-11-25", "2015-11-27", "2015-11-29"] $(function () { $(".datepicker").datepicker({ beforeShowDay: $.datepicker.noWeekends, minDate: 0 }) //$("#startDate").datepicker({ minDate: new Date(), beforeShowDay: $datepicker.noWeekends }); $("#startDate").datepicker(); }); $('input').datepicker({ beforeShowDay: function (date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); return [array.indexOf(string) == -1] } }); $(function () { $('#startDate').datepicker({ beforeShowDay: $.datepicker.noWeekends }); });
HTML
@**@ @Html.TextBox("datetime.now", String.Format("{0:d}", "Start date"), new { @class = "datepicker", type = "text" })
@**@ @Html.TextBox("01-01-2015", String.Format("{0:d}", "End date"), new { @class = "datepicker", type = "text" })
尝试使用datepicker禁止选择arrays中的周末和特定日期。 我如何结合两者? 因为目前只有noWeekends正在运作。 当我注释掉noWeekends部分时,我的数组中的日期不被允许被选中。
只需按照以下方式更改脚本标记即可。
var holidays_dates = ["11-25-2015", "11-27-2015", "11-29-2015","10-9-2015"]; $(function() { $( "#startDate" ).datepicker({ beforeShowDay: function(date){ // First convert the date in to the mm-dd-yyyy format // Take note that we will increment the month count by 1 var current_date = (date.getMonth() + 1) + '-' + date.getDate() + '-' + date.getFullYear() ; //alert(current_date) // We will now check if the date belongs to holidays_dates array if ($.inArray(current_date, holidays_dates) != -1 ) { return [false]; } // In case the date is not present in holidays_dates array, we will now check if it is a weekend. // We will use the noWeekends function var weekend_dates = $.datepicker.noWeekends(date); return weekend_dates; } }); });
尝试:
var disableddates = ["11-25-2015", "11-27-2015", "11-29-2015"]; function DisableSpecificDates(date) { var m = date.getMonth(); var d = date.getDate(); var y = date.getFullYear(); var currentdate = (m + 1) + '-' + d + '-' + y; for (var i = 0; i < disableddates.length; i++) { if ($.inArray(currentdate, disableddates) != -1) { return [false]; } } var weekenddate = $.datepicker.noWeekends(date); return weekenddate; } $(function() { $('#startDate').datepicker({ beforeShowDay: DisableSpecificDates }); });
资料来源: http : //www.spiceforms.com/blog/how-to-disable-dates-in-jquery-datepicker-a-short-guide/
小提琴: http : //jsfiddle.net/6yajfmk2/1/
- Angular 2 datepicker组件,用于禁用特定日期
- 如何从jQuery UI datepicker获取dateFormat?
- jQuery UI DatePicker – 禁用除每月第1天和第15天之外的所有日期
- Jquery DatePicker颜色周日红
- Boostrap datepicker,每月动态禁用日期
- 将setDate与jQueryUi datepicker一起使用
- 如何设置Bootstrap Datepicker的第一天和几周
- jQuery DatePicker:当日期字段为12-31-9999时,currentDate不起作用
- 缩小大小并更改bootstrap-datepicker字段的文本颜色