当我单击按钮时,所有日期选择器都会重新加载,并且不可用的日期适用于所有日期,按钮 One 应该仅在第一个日期选择器中锁定不可用的日期。怎么做?这是代码
function unavailable(date) {
dmy = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
if ($.inArray(dmy, unavailableDates) == -1) {
return [true, ""];
} else {
return [false, "", "Unavailable"];
}
}
var unavailableDates = ['2013-8-19'];
$(function() {
var today = '2013-08-12';
$( "#datepicker1").datepicker({
beforeShowDay: unavailable,
minDate: new Date(today)
});
$( "#datepicker2").datepicker( {
beforeShowDay: unavailable,
minDate: new Date(today)
});
$( "#datepicker3").datepicker({
beforeShowDay: unavailable,
minDate: new Date(today)
});
$("#dp").click(function(){
unavailableDates = ['2013-8-24', '2013-8-25'];
$( "#datepicker2").datepicker( {
beforeShowDay: unavailable,
minDate: new Date(today)
});
});
$("#dp2").click(function(){
unavailableDates = ['2013-8-20', '2013-8-21', '2013-8-22'];
$( "#datepicker3").datepicker({
beforeShowDay: unavailable,
minDate: new Date(today)
});
});
});
<p>Date: <input type="text" id="datepicker1" /></p>
<p>Date: <input type="text" id="datepicker2" /></p>
<p>Date: <input type="text" id="datepicker3" /></p>
<button id ="dp">One</button>
<button id ="dp2">Two</button>