我有这个HTML:
<p>
<label for="checkInDate">Check-in Date:</label>
<input type="date" class="date" id="checkInDate" min="2015-01-01"
value="<?php echo date('Y-m-d'); ?>" />
</p>
有没有办法在用户选择日期时作出回应?使用jquery,on('click')在单击/聚焦元素时触发,但在我实际选择日期时不触发。
我需要检测此事件,以便将结帐日期设置为所选入住日期后的第二天。
编辑:我已触发更改事件,因此现在我想在签入日期添加一天并将结帐日期设置为该值:
var checkInDate = $(this).val();
var tomorrow = new Date(checkInDate);
tomorrow.setDate(checkInDate.getDate() + 1);
$('#checkOutDate').val(tomorrow);
结果
The specified value 'Thu Feb 26 2015 00:00:00 GMT-0700 (Mountain Standard Time)' does not conform to the required format, 'yyyy-MM-dd'.
答案 0 :(得分:2)
您可以使用change
方法。
$('#checkInDate').change(function(){
//Do what you want here
});
答案 1 :(得分:0)
这是一个输入值。所以你应该使用jQuery的.change()事件来跟踪它。
请注意,您可以使用与.click()
事件相同的语法。 I.E. .on('change')