假期和周末的MVC Datepicker [英] MVC Datepicker for both holidays and weekends
本文介绍了假期和周末的MVC Datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Datepicker
<script type="text/javascript">
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 }); });
</script>
Html
<div class="form-group">
<div class="col-md-4 col-md-offset-4">
<label>Start Date</label>
@*<input type="date" class="form-control" id="startDate"/>*@
@Html.TextBox("datetime.now", String.Format("{0:d}", "Start date"), new { @class = "datepicker", type = "text" })
</div>
</div>
<div class="form-group">
<div class="col-md-4 col-md-offset-4">
<br />
<label>End Date</label>
@*<input type="date" class="form-control" id="endDate" />*@
@Html.TextBox("01-01-2015", String.Format("{0:d}", "End date"), new { @class = "datepicker", type = "text" })
</div>
</div>
尝试使用datepicker禁止选择数组中的周末和特定日期。如何组合两者?因为目前只有noWeekends正在工作。
Trying to use datepicker to disallow weekends and specific dates in the array from being selected. How do I combine both? Because currently only the noWeekends is working. Dates in my array are only disallowed from being selected when i comment out the noWeekends part.
推荐答案
只需将脚本标记更改为以下格式即可,否则我的阵列中的日期将被禁止被选中并且它应该工作。
Just change your Script tag as follow and it should work.
<script type="text/javascript">
var array = ["2015-11-25", "2015-11-27", "2015-11-29"]
$('.datepicker').datepicker({
beforeShowDay: function (date) {
var noWeekend = $.datepicker.noWeekends(date);
if (noWeekend[0]) {
return [array.indexOf(jQuery.datepicker.formatDate('yy-mm-dd', date)) == -1]
} else {
return noWeekend;
}
}, minDate: 0
});
$(function () { $('#startDate').datepicker({ beforeShowDay: $.datepicker.noWeekends }); });
</script>
这篇关于假期和周末的MVC Datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文