js日付/時間比較関数、およびjsチェックシートの後にフォームを提出する3つの方法、フォームの検証、および3つの結合


<pre class="html" name="code">

js    (yyyy-mm-dd)

function duibi(a, b) {
var arr = a.split("-");
var starttime = new Date(arr[0], arr[1], arr[2]);
var starttimes = starttime.getTime();

var arrs = b.split("-");
var lktime = new Date(arrs[0], arrs[1], arrs[2]);
var lktimes = lktime.getTime();

if (starttimes >= lktimes) {

alert('          ,   ');
return false;
}
else
return true;

}


js    (yyyy-mm-dd hh:mi:ss)


function comptime() {
var beginTime = "2009-09-21 00:00:00";
var endTime = "2009-09-21 00:00:01";
var beginTimes = beginTime.substring(0, 10).split('-');
var endTimes = endTime.substring(0, 10).split('-');

beginTime = beginTimes[1] + '-' + beginTimes[2] + '-' + beginTimes[0] + ' ' + beginTime.substring(10, 19);
endTime = endTimes[1] + '-' + endTimes[2] + '-' + endTimes[0] + ' ' + endTime.substring(10, 19);

alert(beginTime + "aaa" + endTime);
alert(Date.parse(endTime));
alert(Date.parse(beginTime));
var a = (Date.parse(endTime) - Date.parse(beginTime)) / 3600 / 1000;
if (a < 0) {
alert("endTime !");
} else if (a > 0) {
alert("endTime !");
} else if (a == 0) {
alert("    !");
} else {
return 'exception'
}
}
 
 


 

 

--------------------------------js校验表单后提交表单的三种方法----------------------------------

第一种:

<script type="text/javascript">
         function check(form) {

          if(form.userId.value=='') {
                alert("       !");
                form.userId.focus();
                return false;
           }
       if(form.password.value==''){
                alert("       !");
                form.password.focus();
                return false;
         }
         return true;
         }
</script>
 
<form action="login.do?act=login" method="post">
    
  <input type=text name="userId" size="18" value="" >
<br>
           
<input type="password" name="password" size="19" value=""/>      
 <input type=submit name="submit1" value="  " onclick="return check(this.form)">  

</form>   
第二種類:
<script type="text/javascript">
function check(form) {

if(form.userId.value=='') {
alert("       !");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("       !");
form.password.focus();
return false;
}
return true;
}
</script>


<form action="login.do?act=login" method="post" onsubmit="return check(this)">
    
<input type=text name="userId" size="18" value="" >
<br>
     
<input type="password" name="password" size="19" value=""/> 
<input type=submit name="submit1" value="  "> 

</form> 
 
第三種類:
<script type="text/javascript">
         function check(form) {

          if(form.userId.value=='') {
                alert("       !");
                form.userId.focus();
                return false;
           }
       if(form.password.value==''){
                alert("       !");
                form.password.focus();
                return false;
         }

          document.myform.submit();
}
</script>
 
<form action="login.do?act=login" name="myform" method="post">
    
  <input type=text name="userId" size="18" value="" >
<br>
           
<input type="password" name="password" size="19" value=""/>      
<input type=button name="submit1" value="  " onclick="check(this.form)">  

</form> 
フォームの検証:
<script type=「text/javascript」src=「{path}/js/custom/validator.js」
 
3つの結合:
<script type="text/javascript" src="${path}/js/custom/validator.js"></script>
 
<script language="javascript">

	function check(form) {
		//alert(form.open_date.value);
		var beginTime = form.open_date.value;
	    var endTime = form.bid_date.value;
	    var beginTimes = beginTime.substring(0, 10).split('-');
	    var endTimes = endTime.substring(0, 10).split('-');

	    beginTime = beginTimes[1] + '-' + beginTimes[2] + '-' + beginTimes[0] + ' ' + beginTime.substring(10, 19);
	    endTime = endTimes[1] + '-' + endTimes[2] + '-' + endTimes[0] + ' ' + endTime.substring(10, 19);

	    //alert(beginTime + "aaa" + endTime);
	   // alert(Date.parse(endTime));
	   // alert(Date.parse(beginTime));
	    var a = (Date.parse(endTime) - Date.parse(beginTime)) / 3600 / 1000;
	    if (a < 0) {
	        alert("            !");
	        return false;
	    } else if (a > 0) {
	        //alert("endTime !");
		//document.myform.submit();
	    } else if (a == 0) {
	        alert("            !");
	        return false;
	    } else {
	    	return false;
	    }
	    return true;
	}
		     </script>
 
------------------  ----------------
<form action="${path}/AmAppliaction_add.do"
			method="post" id="myform" name="myform" onSubmit="return Validator.Validate(this,3)">
				<table class="table" cellspacing="0" cellpadding="2" width="99%"
				align="center" border="0">
 
	<input label="    " id="open_date" name="open_date" value="${open_date}"  dataType="Require" msg="        "
												class="Wdate" size="10" readonly="readonly" style="height:15px;width: 184px;"
												 onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"  />
<td class="td_bg"  align="left" colspan="2">
							<input type="submit" name="submit1" value="  " onclick="check(this.form)">  
							<s:reset value="  " cssClass="btn"></s:reset>
						</td>
</form>
------------------検証は先に時間を比較する-------------その後、FORMにトリガJSフォーム検証を提出する--------------