嘿家伙,我有一个约会员,我已经禁用了周末。但问题是用户可以输入周末的日期
$("[name=startdatecontract]").datepicker({
minDate : 2,
beforeShowDay: $.datepicker.noWeekends
});
用户必须能够编写它。但是当我在周末约会时,我需要忽略或给出错误的东西。 +如果日期不是从今天起的2天
答案 0 :(得分:1)
试用此代码
这里我在change
功能
$("#datepicker").datepicker({
minDate : 2,
beforeShowDay: $.datepicker.noWeekends
}).on("change", function(e) {
var curDate = $(this).datepicker("getDate");
var minDate = $( "#datepicker" ).datepicker( "option", "minDate" );
var maxDate = new Date(new Date().setDate(new Date().getDate() + minDate));
var datee=(this.value, curDate)>=maxDate?(this.value, curDate):null;
if(datee!==null){
var day = datee.getDay();
if (day==6||day==0) {
alert("invalid date");
this.value="";
}
}
else{
alert("invalid date");
this.value="";
}
});
$("#datepicker").datepicker({
minDate : 2,
beforeShowDay: $.datepicker.noWeekends
}).on("change", function(e) {
var curDate = $(this).datepicker("getDate");
var minDate = $( "#datepicker" ).datepicker( "option", "minDate" );
var maxDate = new Date(new Date().setDate(new Date().getDate() + minDate));
var datee=(this.value, curDate)>=maxDate?(this.value, curDate):null;
if(datee!==null){
var day = datee.getDay();
if (day==6||day==0) {
alert("invalid date");
this.value="";
}
}
else{
alert("invalid date");
this.value="";
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<div class="block">
<input id="datepicker" type="text" />
</div>
答案 1 :(得分:0)
defined()