相信在處理from表單的提交時(shí),大家可能會(huì )遇到這樣的業(yè)務(wù)需求,當點(diǎn)擊提交按鈕時(shí)需要先提交到一個(gè)JavaScript中驗證,然后再提交到服務(wù)器。
看看下面的例子: - <html>
- <head><title></title></head>
- <body>
- <form name="form1" id="form1" method="post" action="form_submit.jsp" >
- <br><br>
- <table>
- <tr>
- <td>公司名稱(chēng)</td>
- <td><input name="consumer_name" id="consumer_name" value="XX公司" /></td>
- </tr>
-
-
- <tr>
- <td></td>
- <td><input type="button" name="submit"
- value="提交" onclick="submit_form();" /></td>
- </tr>
- </table>
- </form>
- </body>
- </html>
- <script type=text/JavaScript>
- function submit_form(){
-
- document.forms[0].submit();
-
- }
- </script>
<html><head><title></title></head><body><form name="form1" id="form1" method="post" action="form_submit.jsp" ><br><br><table> <tr> <td>公司名稱(chēng)</td> <td><input name="consumer_name" id="consumer_name" value="XX公司" /></td> </tr> <tr> <td></td> <td><input type="button" name="submit" value="提交" onclick="submit_form();" /></td> </tr></table></form></body></html><script type=text/JavaScript>function submit_form(){ document.forms[0].submit(); }</script>但這樣提交后會(huì )遇到這樣的問(wèn)題form表單不會(huì )提交出去,問(wèn)題是你的button按鈕的name是"submit",他是JavaScript的關(guān)鍵字,form表單不會(huì )提交,只要把它改了,就ok了,這也是我在開(kāi)發(fā)時(shí)遇到的一個(gè)問(wèn)題。與大家分享。