表单输入enter后,自动提交的发生条件
* Opera、Safari浏览器
有<input type="text">或<input type="password">标签时
例如:
<form>
<input type = "text" name = "text1">
<input type = "text" name = "text2">
</form>
* IE、Firefox浏览器
有1个以上<input type="text">或<input type="password">标签、且有1个以上<input type="submit">或<input type="image">标签时,
例如:
<form>
<input type = "text" name = "text">
<input type = "submit" name = "button1″ value = "送信">
</form>
* IE、Firefox浏览器
只有1个<input type="text">或<input type="password">标签、且没有<input type="submit">或<input type="image">标签时,
例如:
<form>
<input type = "text" name = "text">
</form>
如何避免自动提交(IE为主):
1, 有多个<input type="text">或<input type="password">标签时,将submit变成button方式。
2, 如果只有1个<input type="text">或<input type=password">标签、且没有<input type="submit">或<input type="image">标签时,在form标签中加入οnsubmit="return false;"属性,或者在form中追加隐藏项目<input type="text" style="display: none;"/>标签。
3,在onkeypress过滤掉enter。
function submitStop(e){
if (!e) var e = window.event;
if(e.keyCode == 13)
return false;
}
οnkeypress="return submitStop(event);"