问题
I have two input date field, one generates a date through JQuery datepicker, I wanr the second to take the value from the first input via onblur or onchange event, it works fine when I enter the date manually, but once entered through the datepicker, it won't fire the second input
here is my Jquery code:
<script type="text/javascript">
$(function () {
var duration=0;
$('#date1').datepicker({ minDate: +1,onSelect: function(selectedDate) {
var date = $(this).datepicker('getDate');
date.setDate(date.getDate() + parseInt(duration)); // Add 7 days
}});
});
</script>
and here is the html code for the inputs:
<input name="date1" type="text" id="date1" onchange="document.zipad.date1_end.value=document.zipad.date1.value" />
</div>
<div id="warning_moderation"></div></td>
<div id="mydate"></div>
<td><div id="warning1">Please allow 24 Hours for moderation before your ads will be published</div></td>
</tr>
<tr>
<td height="44">Ending Date:<br/>
<input name="date1_end" type="text" id="date1_end" disabled="disabled"/>
回答1:
$('#date1').datepicker({ minDate: +1,onSelect: function(selectedDate) {
var date = $(this).datepicker('getDate');
date.setDate(date.getDate() + parseInt(duration)); // Add 7 days
$('#date1').trigger('change');
}});
来源:https://stackoverflow.com/questions/19149092/datepicker-wont-fire-an-onchange-event