[英]Jquery Ui date time picker
I am using jquery date time picker and using start date
and end date
. 我正在使用jquery日期时间选择器,并使用
start date
和end date
。
When selecting same date for start date
and end date
I do not want it to allow the end date
time to be less than start date
time. 当选择相同的日期作为
start date
和end date
我不希望它允许end date
时间小于start date
时间。 How would I adjust my code? 如何调整代码?
$( "#fdate" ).datetimepicker({
dateFormat: 'yy-mm-dd',timeFormat: 'HH:mm:ss',
onClose: function( selectedDate ) {
$( "#tdate" ).datetimepicker( "option", "minDate", selectedDate );
}
}).attr('readonly', 'readonly');
$( "#tdate" ).datetimepicker({dateFormat: 'yy-mm-dd',timeFormat: 'HH:mm:ss',
onClose: function( selectedDate ) {
$( "#fdate" ).datetimepicker( "option", "maxDate", selectedDate );
}
}).attr('readonly', 'readonly');
});
here fdate is start date and tdate is end date and here is Fiddle of the issue 这里的fdate是开始日期,而tdate是结束日期,这是问题的提琴
You need to use the 'setOptions' method for each timepicker: 您需要为每个时间选择器使用'setOptions'方法:
$(document).ready(function(){
$("#fdate" ).datetimepicker({
dateFormat: 'yy-mm-dd',
timeFormat: 'HH:mm:ss',
onShow: function () {
this.setOptions({
maxDate:$('#tdate').val()?$('#tdate').val():false,
maxTime:$('#tdate').val()?$('#tdate').val():false
});
}
}).attr('readonly', 'readonly');
$( "#tdate" ).datetimepicker({
dateFormat: 'yy-mm-dd',
timeFormat: 'HH:mm:ss',
onShow: function () {
this.setOptions({
minDate:$('#fdate').val()?$('#fdate').val():false,
minTime:$('#fdate').val()?$('#fdate').val():false
});
}
}).attr('readonly', 'readonly');
Here is the Modified Fiddle . 这是改良的小提琴 。
This is not perfect, but it will get you close, you may need to handle some of the formatting. 这不是完美的方法,但是它会让您接近,您可能需要处理一些格式。 I used the 'onShow' event, but you could easily do it in the onClose, as well.
我使用了'onShow'事件,但是您也可以在onClose中轻松地完成它。 There is a small sample on their official page called Range between date# .
在他们的官方页面上有一个名为date between date#的小样本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.