JS判断结束时间不能小于开始时间并且间隔不能超过31天

<html>
  <head>
     <title></title>
  </head>
  <body>
     <form method="post">
         起始时间:<input id="first" type="text"/><br><!-- 2012-05-01 -->
         终止时间:<input id="second" type="text"/>
         <input type="submit" id="submit" name="提交"/>
     </form>
  </body>
  <script type="text/javascript">
     
	var first = document.getElementById("first").value;
        var second = document.getElementById("second").value;
 var data1 = Date.parse(first.replace(/-/g,   "/"));
    var data2 = Date.parse(second.replace(/-/g,   "/"));
    var datadiff = data2-data1;
    var time = 31*24*60*60*1000;     
if(first.length>0 && second.length>0){
          if(datadiff<0||datadiff>time){
             alert("开始时间应小于结束时间并且间隔小于31天,请检查!");
             return false;
          }
} 
</script>
</html>

你可能感兴趣的:(html,input)