我目前正在开发一个网站,其中包含与date& amp;时间。对于时间指示器,我使用了" jquery datepicker addon"。 但问题是,日期选择器不会更新他的小时/时间输入值。因此,当您选择日期时,日期输入会更新并显示datepicker(inspect元素)的值,但不会显示次输入的值。您可以通过检查代码来看到这一点。
请参阅printscreen:http://nl.tinypic.com/r/35816jb/8
HTML代码:
<p>Date: <input type="text" name="datumtijd-aanduiding" id="datumtijd-aanduiding" value=""/> On: <input type="text" name="datumtijd-aanduiding-tijd" id="datumtijd-aanduiding-tijd" value=""/></p>
到目前为止的JS代码:
$( document ).ready(function() {
$("#datumtijd-aanduiding").datepicker({
dateFormat: "DD, d MM yy",
onSelect: function (dateText, instance) {
$('#datumtijd-aanduiding').text(this.value);
var date = $.datepicker.parseDate("DD, d MM yy", dateText);
var isWeekendHours = !$.datepicker.noWeekends(date)[0];
if (isWeekendHours) {
$("#datumtijd-aanduiding-tijd").removeClass("hasDatepicker");
$("#datumtijd-aanduiding-tijd").timepicker({
hourMin: 12,
hourMax: 17,
stepMinute: 5,
timeOnly: true,
timeFormat: "HH:mm"
});
} else {
$("#datumtijd-aanduiding-tijd").removeClass("hasDatepicker");
$("#datumtijd-aanduiding-tijd").timepicker({
hourMin: 8,
hourMax: 22,
stepMinute: 5,
timeOnly: true,
timeFormat: "HH:mm"
});
}
},
//set options
minDate: 0,
numberOfMonths: 1,
showButtonPanel: true,
changeMonth: true,
changeYear: false,
selectWeek: true
}).datepicker("setDate", "0");
});
工作的jsfiddle链接:http://goo.gl/G6bK9I
答案 0 :(得分:2)
我对daterangepicker有同样的问题
我用过
$('#startDate').daterangepicker({
"singleDatePicker": true,
"timePicker": true,
locale: {
format: 'MM/DD/YYYY h:mm A'
}
});