在我的一个项目中,我需要提供以下功能。我正在使用来自此源的jQueryUi datepicker和timepicker插件(http://jonthornton.github.io/jquery-timepicker/)
这应该随着日期字段的变化而变化。所以我认为必须使用.change()
。我试过用它。它在第一次选择时会发生变化,但如果我再次更改相同的日期字段,则timepicker字段不会更改。这是关于jsfiddle的代码:http://jsfiddle.net/vivpad/262x159b/
<div class="row">
<div class="small-6 columns">
<label>TimePicker
<input type="text" class="timepicker">
</label>
</div>
<div class="small-6 columns">
<label>DatePicker
<input type="text" class="datepicker">
</label>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.8.7/jquery.timepicker.min.js"></script>
使用了Jquery,jQueryUI和以上的timepicker脚本
var fullDate = new Date();
console.log(fullDate);
var twoDigitMonth = (fullDate.getMonth() + 1) + "";
if (twoDigitMonth.length == 1) twoDigitMonth = "0" + twoDigitMonth;
var twoDigitDate = fullDate.getDate() + "";
if (twoDigitDate.length == 1) twoDigitDate = "0" + twoDigitDate;
var currentDate = twoDigitDate + "/" + twoDigitMonth + "/" + fullDate.getFullYear();
console.log(currentDate);
var dt = new Date();
var currentTime = dt.getHours() + ":" + dt.getMinutes();
console.log(currentTime);
$('.timepicker').timepicker({
'minTime': '10.00am',
'maxTime': '11:30pm',
'showDuration': true
});
$("#datepicker, .datepicker").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy'
});
$('.datepicker').change(function () {
});