我在 2 个具有 #start_time 和 #end_time id 的文件上使用 jQuery timepicker 插件( https://github.com/trentrichardson/jQuery-Timepicker-Addon )。我希望#end_time 必须更大或从#start_time 的时间开始。我尝试了下面的代码,但我不擅长 jQuery。
$(function() {
$('#start_time').timepicker({
onClose: function(timeText, inst) {
if ($('#end_time').val() != '') {
var testStartTime = $('#start_time').timepicker('getTime');
var testEndTime = $('#end_time').timepicker('getTime');
if (testStartTime > testEndTime)
$('#end_time').timepicker('setTime', testStartTime);
}
else {
$('#end_time').val(timeText);
}
},
onSelect: function (selectedTime){
$('#end_time').timepicker('option', 'minTime', $('#start_time').timepicker('getTime') );
}
});
$('#end_time').timepicker({
onClose: function(timeText, inst) {
if ($('#start_time').val() != '') {
var testStartTime = $('#start_time').timepicker('getTime');
var testEndTime = $('#end_time').timepicker('getTime');
if (testStartTime > testEndTime)
$('#start_time').timepicker('setTime', testEndTime);
}
else {
$('#start_time').val(timeText);
}
},
onSelect: function (selectedTime){
$('#start_time').timepicker('option', 'maxTime', $('#end_time').timepicker('getTime') );
}
});
});
我有两个时间输入 start_time 和 end_time。