Form表單提交,js驗證
1, Onclick()
2, Onsubmit()
Button標簽 input (屬性 submit button )標簽
Input type=button 定義按鈕,沒有任何行為。多數情況下,用於通過javascript啟動腳本
Input type=submit 定義提交按鈕,提交按鈕會把表單數據發送到服務器
1, onclick 與 Input type=submit 搭配
<form action=”XXXX” method=”post” >
<input type=”text” name=”nihao” >
<input type=”submit” value=”提交” onclick=”return check(this.from) ” >
</form>
Function check(form){
//這個form參數代表html中的表單元素集合
Form.nihao代表是 <input type=”text” name=”nihao” >真個標簽
Var info =form.nihao.value;
}
在javascript中,事件調用函數時,用return返回值實際上是對window.event.returnValue進行設置
而該值決定當前操作是否繼續,true是繼續 false中斷
第二種方法:onsubmit 與 Input type=submit 搭配
上述兩種方法的 Input type=submit 等同於 button標簽
第三種方法:onclick 與 Input type=button 搭配
注意:Input type=button 提交不會觸發form的 onsubmit事件