form表单按enter键自动提交的问题
摘要:废话不多说。直接上代码。1:form表单按enter键自动提交的情况 1 2 3 4 5 6 7 8 9 Document10 11 12 13 14 15 16 17 在此文本框中按enter键,页面会自动跳转...
废话不多说。直接上代码。
1:form表单按enter键自动提交的情况
1 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
<form method="post" action="http:www.baidu.com">
<input>
<textarea name="text" cols="20" rows="5" />
</form>
</body>
</html>
在此文本框中按enter键,页面会自动跳转到百度的搜索页面。
2:解决方案
1)去掉form表单。然后在文本框中按enter键就不会出现自动跳转的情况了。(不建议使用)
2)再添加一个隐藏的文本框。出现问题的原因是form表单中有且只有一个文本框。故新增一个隐藏的文本框也可解决问题。
<input style="display:none"/>
3)在表单上添加属性 onsubmit="return false";也可以解决问题。
相关文章
最新发布
阅读排行
热门文章
猜你喜欢