<!
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下阻塞表单的提交,而其他浏览