废话不多说。直接上代码。
1:form表单按enter键自动提交的情况
04 | < meta charset = "UTF-8" > |
05 | < meta name = "Generator" content = "EditPlus®" > |
06 | < meta name = "Author" content = "" > |
07 | < meta name = "Keywords" content = "" > |
08 | < meta name = "Description" content = "" > |
09 | < title >Document</ title > |
12 | < form method = "post" action = "http:www.baidu.com" > |
14 | < textarea name = "text" cols = "20" rows = "5" /> |
在此文本框中按enter键,页面会自动跳转到百度的搜索页面。
2:解决方案
1)去掉form表单。然后在文本框中按enter键就不会出现自动跳转的情况了。(不建议使用)
2)再添加一个隐藏的文本框。出现问题的原因是form表单中有且只有一个文本框。故新增一个隐藏的文本框也可解决问题。
<input style="display:none"/>
3)在表单上添加属性 onsubmit="return false";也可以解决问题。