<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< title >無標題文檔 </ title >
</ head >
< body >
< script >
function test()
{
document.getElementById("myform").submit();
alert(11);
}
</ script >
< form name ="myfrom" id ="myform" method ="get" action ="b.php" >
< input type ="text" name ="pwd" value ="" />
< input type ="submit" name ="sub" value ="111" />
< input type ="button" name ="btn" value ="btn" onclick ="test()" />
</ form >
</ body >
</ html >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< title >無標題文檔 </ title >
</ head >
< body >
< script >
function test()
{
document.getElementById("myform").submit();
alert(11);
}
</ script >
< form name ="myfrom" id ="myform" method ="get" action ="b.php" >
< input type ="text" name ="pwd" value ="" />
< input type ="submit" name ="sub" value ="111" />
< input type ="button" name ="btn" value ="btn" onclick ="test()" />
</ form >
</ body >
</ html >
注意:get方式提交表單時 action里面不能用url傳值, post則可以這樣傳
js提交和submit按鈕提交的區別:
1. js提交表單時不會帶上 submit 按鈕的值(因為沒有被單擊) 所有瀏覽器
2. input 回車提交 w3c瀏覽器會帶上submit按鈕的值,ie6則不會帶
解決辦法:增加一個hidden域,用這個來判斷,無論用哪種方式提交都會有值
submit按鈕上綁定提交事件:
即:<input type="submit" name="btn" value="btn" onclick="test()" />
都會帶上submit的值, 用js提交都檢測不到onsubmit狀態
w3c: 提交一次
ie6: 分兩次提交,先js在form提交
解決辦法:如果按鈕為submit則 檢測時用onsubmit事件檢測
如果按鈕為button,則檢測通過后在觸發submit事件
一定不要用js提交表單,然后又用onsubmit去檢測
單純的用js提交表單, alert, ff下阻塞表單的提交,而其他瀏覽