form表单的两种提交方式,submit和button的用法
方法一:
在jsp的前端頁(yè)面的頭部插入一個(gè)js方法:
?function checkUser(){
?? var result = document.getElementById("userid").value;
?? var password = document.getElementById("userpassid").value;
?? if(result == ""? ){
???? alert("用戶名不能為空");
???? return false;
?? }
?? if(password == ""? ){
??? alert("密碼不能為空");
???? return false;
?? }else{
?? return true;
?? }
}
在form表單里寫成這樣:
<form id="formid"? name= "myform" method = 'post'? action = 'user_login_submit.action'?onsubmit = "return checkUser();" >
??????????? <table width="100%" border="0">
????????????? <tr>
??????????????? <td width="60" height="40" align="right">用戶名 </td>
??????????????? <td><input type="text" value="" class="text2" name = "username" id = "userid"/></td>
????????????? </tr>
????????????? <tr>
??????????????? <td width="60" height="40" align="right">密 碼 </td>
??????????????? <td><input type="password" value="" class="text2" name = "userpass" id = "userpassid"/></td>
????????????? </tr>
????????????? <tr>
??????????????? <td width="60" height="40" align="right"> </td>
??????????????? <td><div class="c4">
??????????????????? <input type="submit" value="" class="btn2"? />
方法二:
function checkUser(){
?? var result = document.getElementById("userid").value;
?? var password = document.getElementById("passid").value;
?? if(result == ""? ){
???? alert("用戶名不能為空");
???? return false;
?? }
?? if(password == ""? ){
??? alert("密碼不能為空");
???? return false;
?? }
? document.getElementById("formid").submit();
}
form表格的寫法,需要寫id
?<form id="formid" method = 'post'? action = 'user_login_submit.action'? >
button按鈕的寫法如下:
<input type="button" value="" class="btn2" onclick = "checkUser();" />
總結(jié)
以上是生活随笔為你收集整理的form表单的两种提交方式,submit和button的用法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: JS 提交form表单
- 下一篇: button和sumbit提交表单的区别