日期:2014-05-16  浏览次数:20395 次

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> 

?

?

//搜索
	function subForm(id) {
		//验证文本框不能为空
		var validValue = $("#"+id).valid();
		if (validValue) {
			var startTime = $("#search_EQ_startTime").val();	
			var endTime = $("#search_EQ_endTime").val();
			
			var data1 = Date.parse(startTime.replace(/-/g,   "/"));  
		    var data2 = Date.parse(endTime.replace(/-/g,   "/"));  
		    var datadiff = data2-data1;  
		    var time = 31*24*60*60*1000; 
		    
		    if(startTime.length>0 && endTime.length>0){  
		          if(datadiff<0||datadiff>time){  
		             alert("开始时间应小于结束时间并且间隔小于31天,请检查!");  
		             return false;  
		          }else{
		        	  $("#" + id).submit();
		          }  
			}   
		}
		
	}

?

?