<html>
<head>
<script> function checkTime(){ var startTime = document.getElementById("_startTime").value.trim(); var endTime = document.getElementById("_endTime").value.trim(); if(startTime == "" || endTime == ""){ alert("时间不能为空"); return ; } var reg = /^((20|21|22|23|[0-1]\d)\:[0-5][0-9])(\:[0-5][0-9])$/; if(!reg.test(startTime) || !reg.test(endTime)){ alert("您输入的时间格式不正确!"); return ; } var startTimeArray = startTime.split(":"); var endTimeArray = endTime.split(":"); var startDate = new Date(startTimeArray[0],startTimeArray[1],startTimeArray[2]); var endDate = new Date(endTimeArray[0],endTimeArray[1],endTimeArray[2]); var start = startDate.getTime(); var end = endDate.getTime(); if (start >= end) { alert('开始时间不能大于结束时间'); return ; } document.getElementById('form1').submit(); } </script>
</head>
<body>
<p>开始时间:<input id="_startTime" value="00:00:00"></p>
<p>结束时间:<input id="_endTime" value="12:00:00"></p>
<input type="button" value="提交" onclick="checkTime()" />
</body>
</html>