我有以下代码,可以将结束时间更新为30分钟。但是,我想检查用户是否将结束时间更改为小于开始时间,然后将开始时间更新为同一时间或禁用输入。这个想法是用户不能在开始时间之前设置结束时间。
我的HTML:
<li data-role="fieldcontain">
<label for="starttime">Start Time</label>
<input name="starttime" type="date" data-role="datebox" id="starttime" readonly data-options='{"mode": "timebox", "timeFormat": 12}' />
<label for="endtime">End Time</label>
<input name="endtime" type="date" data-role="datebox" id="endtime" readonly data-options='{"mode": "timebox", "timeFormat": 12}' />
</li>
我的Jquery:
$('#starttime').live('change', function() {
var currentTime=new Date();
var starttime=sealtime.timeto24HoursFormat($('#starttime').val());
if(starttime.split(":").length>1){
currentTime.setHours(starttime.split(":")[0]);
currentTime.setMinutes(starttime.split(":")[1]);
currentTime.setMinutes(currentTime.getMinutes()+30);
}
var hours=currentTime.getHours().toString();
if(hours<10)
hours='0'+hours;
var minutes=currentTime.getMinutes().toString();
if(minutes<10)
minutes='0'+minutes;
$('#endtime').val(sealtime.timeto12HoursFormat(hours+':'+minutes+":00"));
});
$('#endtime').live('change', function() {
var currentTime=new Date();
var endtime=sealtime.timeto24HoursFormat($('#endtime').val());
var starttime=sealtime.timeto24HoursFormat($('#starttime').val());
if(endtime.split(":").length>1){
currentTime.setHours(endtime.split(":")[0]);
currentTime.setMinutes(endtime.split(":")[1]);
currentTime.setMinutes(currentTime.getMinutes()-0);
}
if (endtime.split(":").length < starttime.split(":").length){
var hours=currentTime.getHours().toString();
if(hours<10)
hours='0'+hours;
var minutes=currentTime.getMinutes().toString();
if(minutes<10)
minutes='0'+minutes;
$('#starttime').val(sealtime.timeto12HoursFormat(hours+':'+minutes+":00"));
}
});