<pre class= "html" name= "code" >JS date comparison (YYYY-MM-DD) function Duibi (A, b) {var arr = a.split ("-"); var starttime = new Dat E (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 (' Start time is greater than departure time, please check '); return false;} Elsereturn true;} JS Time comparison (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). Split ('-'); var endtimes = endtime.substring (0). Split ('-'); beginTime = BEGINTIMES[1] + '-' + begintimes[2] + '-' + begintimes[0] + ' + begintime.substring (ten, +); endTime = endtimes[1] + '-' + endtimes[2] + '-' + endtimes[0] + ' + endtime.substring (+ +), alert (BeginTime + "AAA" + endTime), alert (Date.parse (en DTime), alert (Date.parse (BeginTime)), var a = (Date.parse (endTime)-Date.parse (BeginTime))/3600/1000;if (a < 0) {AL ERT ("Endtime small!");}else if (a > 0) {alert ("Endtime"),} else if (a = = 0) {alert ("Equal time!");} else {return ' exception '}}
Three ways to submit a form after--------------------------------JS check form----------------------------------
The first type:
<script type= "Text/javascript" > function Check (form) { if (form.userid.value== ') { alert (" Please enter user account! "); Form.userId.focus (); return false; } if (form.password.value== ') { alert ("Please enter login password!"); Form.password.focus (); return false; } return true; } </script> <form action= "Login.do?act=login" method= "POST" > User account <input type=text name= "UserId" Size= "value=" "><br> login password <input type=" password "name=" password "size= " value= "/> <input type=submit name= "submit1" value= "Login" onclick= "return Check (this.form)" > </form>
The second type:
The third type:
<script type= "Text/javascript" > function Check (form) { if (form.userid.value== ') { alert (" Please enter user account! "); Form.userId.focus (); return false; } if (form.password.value== ') { alert ("Please enter login password!"); Form.password.focus (); return false; } Document.myform.submit ();} </script> <form action= "Login.do?act=login" name= "MyForm" method= "POST" > User account <input type=text Name= "UserId" size= "value=" "><br> login password <input type=" password "name=" password "size=" "value=" " /> <input Type=button name= "submit1" value= "Login" onclick= "Check (this.form)" >
Form validation:
<script type= "Text/javascript" src= "${path}/js/custom/validator.js" ></script>
Three kinds of combinations:
<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, ten). Split ('-'); var endtimes = endtime.substring (0, ten). 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 ("Bid time must be later than bid opening time!"); return false; } else if (a > 0) {//alert ("Endtime big!"); /document.myform.submit (); } else if (a = = 0) {alert ("Bid time must be later than bid opening time!"); return false; } else {return false; } return true; </script>
------------------form----------------
<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= "Bid Opening time" id= "Open_date" name= "Open_date" value= "${open_date}" datatype= "Require" msg= "bid Opening time cannot be empty" class= "Wdate" size= "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= "Submit" onclick= " Check (this.form) "> <s:reset value=" reset "cssclass=" BTN "></s:reset></td>
</form>
--------------------------validation compares the time-------------------and then the form commits to trigger the JS form validation------------------------
JS Date/Time comparison function, and three ways to submit a form after the JS check form, form validation, and three combinations