form 填完文本框安enter键表单自动交付

form 填完文本框安enter键表单自动提交

在表单form中,包含text和submit,当焦点在text内,如果直接按回车,页面不会像点击submit按钮那样执行验证代码,会直接提交掉。(基本发生在表单内只有一个text文本域的时候)

If you have a Web Form with just one single-line text input (even if there are additional input fields, like CheckBoxLists, RadioButtonLists, DropDownLists, and so on), hitting enter in the text input will not cause the Button Web control's Click event to fire when using Internet Explorer

解决方法:
1.增加 form 的 onsubmit 事件来阻止表单自动提交:(IE和火狐下测试通过,推荐)
  <form name="testForm" method="post" action="/testAction.do" onsubmit="return false;">

2.在页面 form 中增加一个 <input style="display:none">

3.用 button 取代 submit :
  <input type='button' value='确定' onclick='document.formname.submit()'>