///这些都是本人实测之后应用到开发当中的代码,可以直切复制使用//
<!DOCTYPE html>
<html><head>
<meta charset="UTF-8"> <meta <title></title> <script src="jquery-1.8.2.min.js" type="text/javascript" charset="utf-8"></script> <!--<script src="js-test.js" type="text/javascript" charset="utf-8"></script>--> <script type="text/javascript"> function tijiao() { if(document.duibi.start.value==''){ alert('start不能为空'); return false; } if(document.duibi.end.value==''){ alert('end不能为空'); return false; } var endtime = $('#end').val(); var starttime = $('#start').val(); var Start = new Date(starttime).getTime(); var End = new Date(endtime).getTime(); if (End < Start) { alert('结束日期不能小于开始日期!'); document.duibi.end.focus(); return false; } } </script> </head><body>
<div class="quan"> <form action="" method="post" name="duibi" id="duibi" οnsubmit="return tijiao()" > <p><span>开始时间</span><input type="date" name="start" id="start" value="" /></p> <p><span>结束时间</span><input type="date" name="end" id="end" value="" /></p> <input type="submit" value="对比时间demo"/> </form> </div> </body></html>