我有两个输入,我已经将jQuery UI Datepickers附加到它们两个。问题是,当我更改第一个上的日期时,它会在第二个上更改,反之亦然。建议?
<label for="datestart">Start Date:</label>
<input id="datestart" name="datestart" type="text">
<label for="dateend">End Date:</label>
<input id="dateend" name="dateend" type="text">
$(function(){
var dates = $('#datestart, #dateend').datepicker({
defaultDate: '+1w', dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true, numberOfMonths: 1, showOtherMonths: true, selectOtherMonths: true,
onSelect: function(selectedDate) {
var option = this.id == 'from' ? 'minDate' : 'maxDate';
var instance = $(this).data('datepicker');
var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
dates.not(this).datepicker('option', option, date);
}
});
});
答案 0 :(得分:1)
您的'from'
需要'datestart'
。
var option = this.id == 'datestart' ? 'minDate' : 'maxDate';