问题描述:
在表单form中,包含text和submit,当焦点在text内,如果直接按回车,页面不会像点击submit按钮那样执行验证代码,会直接提交掉。(基本发生在表单内只有一个text文本域的时候)
[u]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[/u]
解决方法:
1.增加 form 的 onsubmit 事件来阻止表单自动提交:(IE和火狐下测试通过,推荐)
<form name="testForm" method="post" action="/testAction.do" [b]onsubmit="return false;"[/b]>
2.在页面 form 中增加一个 [b]<input style="display:none">[/b]
3.用 button 取代 submit :
<input type='button' value='确定' onclick='document.formname.submit()'>
问题虽小,解决起来却费了大力气,N多JSP一一修改,算是个教训吧。
在表单form中,包含text和submit,当焦点在text内,如果直接按回车,页面不会像点击submit按钮那样执行验证代码,会直接提交掉。(基本发生在表单内只有一个text文本域的时候)
[u]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[/u]
解决方法:
1.增加 form 的 onsubmit 事件来阻止表单自动提交:(IE和火狐下测试通过,推荐)
<form name="testForm" method="post" action="/testAction.do" [b]onsubmit="return false;"[/b]>
2.在页面 form 中增加一个 [b]<input style="display:none">[/b]
3.用 button 取代 submit :
<input type='button' value='确定' onclick='document.formname.submit()'>
问题虽小,解决起来却费了大力气,N多JSP一一修改,算是个教训吧。
本文介绍了解决表单中仅含单行文本输入时,按下Enter键不会触发按钮Click事件的问题。提供了三种解决方法:增加form的onsubmit事件阻止自动提交、增加隐藏的input元素以及使用button代替submit。
531

被折叠的 条评论
为什么被折叠?



