jQuery datetimepicker插件范围错误 [英] jQuery datetimepicker plugin range bug
问题描述
我正在使用以下jQuery插件: https://github.com/xdan/datetimepicker 实现一个开始和结束日期,其中结束不能在开始之前,并且开始不能在结束之后。根据文档中的示例(我需要时间和日期),我的代码如下: http ://xdsoft.net/jqplugins/datetimepicker/#range
I am using the following jQuery plugin: https://github.com/xdan/datetimepicker to implement a start and end date, where the end cannot be before the start and the start cannot be after the end. My code is bellow, based off the example in the documentation (I need the time as well as date): http://xdsoft.net/jqplugins/datetimepicker/#range
问题是没有设置限制。从代码我可以看到 https://github.com/ xdan / datetimepicker / blob / master / jquery.datetimepicker.js#L509 需要 minDate
和 maxDate
在他们面前有一个 - +
。这是一个错误还是我错过了什么?
The problem is that limits aren't being set. From the code I can see that https://github.com/xdan/datetimepicker/blob/master/jquery.datetimepicker.js#L509 requires the minDate
and maxDate
to have a -+
in front of them. Is this a bug or am I missing something?
var format = "Y-m-d H:i:s";
var startSelector = "input[type='datetime-picker'][name='start']";
var endSelector = "input[type='datetime-picker'][name='end']";
$(startSelector).datetimepicker( {
format : format,
onShow : function(ct) {
var val = $(endSelector).val();
console.log('start max val: '+val);
var opts = {
formatDate : "Y-m-d",
maxDate : val ? '+'+val.split(' ')[0] : false
};
this.setOptions(opts);
},
});
$(endSelector).datetimepicker( {
format : format,
onShow : function(ct) {
var val = $(startSelector).val();
console.log('end min val: '+val);
var opts = {
formatDate : "Y-m-d",
minDate : val ? '-'+
val.split(' ')[0] : false
};
this.setOptions(opts);
},
});
推荐答案
您可以使用默认脚本http://xdsoft.net/jqplugins/datetimepicker/
但你应该知道它的格式是完美的Y / m / d 。
You can use the default script http://xdsoft.net/jqplugins/datetimepicker/ but you should know that it work perfectly for the format Y/m/d.
如果你想改变格式,别忘了再把你的格式放在最小/最大日期旁边
If you want to change the format dont forget to put again your format next to the Min/Max date
这是我的脚本的一个例子,它适用于任何格式:
here is an example of my script it work perfectly for any format:
jQuery(function(){
jQuery('#date_timepicker_start').datetimepicker({
format:'d/m/Y - H:i',
onShow:function( ct ){
this.setOptions({
minDate:0,
maxDate:jQuery('#date_timepicker_end').val()?jQuery('#date_timepicker_end').val():false,formatDate:'d/m/Y - H:i'
})
},
timepicker:true,
step : 60,
lang: 'en',
});
jQuery('#date_timepicker_end').datetimepicker({
format:'d/m/Y - H:i',
onShow:function( ct ){
this.setOptions({
minDate:jQuery('#date_timepicker_start').val()?jQuery('#date_timepicker_start').val():false,formatDate:'d/m/Y - H:i'
})
},
timepicker:true,
step : 60,
lang: 'en',
});
});
这篇关于jQuery datetimepicker插件范围错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!