我想根据以下情况更改日期: -
情况1: - 如果我选择" From"以日期为例:(2014-12-7)," To"日期与" From"相同。
情况2: - 如果用户想要更改日期并选择" To"约会日期" To"。
这是我的代码:
<script>
var holidays = ['2014/5/1', '2014/8/31', '2014/12/26'];
function highlightDays(date) {
for (var i = 0; i < holidays.length; i++) {
if (new Date(holidays[i]).toString() == date.toString()) {
return [true, 'highlight'];
}
}
return [true, ''];
}
$(function () {
$("#datepicker").datepicker({
minDate: 0,
maxDate:"+60D",
dateFormat: 'yy/mm/dd',
showAnim: "fold",
inline: false,
numberOfMonths: [1,2],
onSelect: function(selected) {
$("#datepicker1").datepicker("option","minDate", selected)
},
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
beforeShowDay: setCustomDate // <-----change function
});
});
$(function () {
$("#datepicker1").datepicker({
minDate: 0,
maxDate:"+60D",
dateFormat: 'yy/mm/dd',
showAnim: "fold",
inline: false,
numberOfMonths: [1,2],
onSelect: function(selected) {
$("#datepicker").datepicker("option","maxDate", selected)
},
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
beforeShowDay: setCustomDate // <-----change function
});
});
function fillDate() {
datevalue = document.getElementById('datepicker').value;
document.getElementById('datepicker1').value= datevalue;
}
var disabledDays = ['2014/5/1', '2014/8/31', '2014/12/26'];
function disableAllTheseDays(date) {
var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
for (i = 0; i < disabledDays.length; i++) {
if($.inArray(y + '/' + (m+1) + '/' + d,disabledDays) != -1) {
return [false];
}
}
return [true];
}
$(function() {
$( "#availability" ).datepicker({
minDate: 0,
dateFormat: 'yy/mm/dd',
inline: true,
numberOfMonths: [1, 2],
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
beforeShowDay: $.datepicker.noWeekends
});
});
function setCustomDate(date) {
var clazz = "";
var arr1 = highlightDays(date);
if (arr1[1] != "") clazz = arr1[1];
var arr2 = disableAllTheseDays(date);
var arr3 = $.datepicker.noWeekends(date);
return [(!arr2[0] || !arr3[0]) ? false : true, clazz];
}
</script>
<input type="text" id="datepicker" class="dp" onchange="fillDate(this.form)" readonly name="leavefromdate" value="From" required>
<br><br>
<input type="text" id="datepicker1" class="dp1" onclick="this.value='';" readonly name="leavetodate" value="To" required>