首页 > HTML/CSS

form表单按enter键自动提交的问题

发表于2015-07-27 14:53:12| 1111次阅读| 来源webkfa| 作者html,css

摘要:废话不多说。直接上代码。1:form表单按enter键自动提交的情况 1 2 3 4 5 6 7 8 9 Document10 11 12 13 14 15 16 17 在此文本框中按enter键,页面会自动跳转...

 废话不多说。直接上代码。

1:form表单按enter键自动提交的情况

011 <!doctype html>
02<html lang="en">
03 <head>
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>
10 </head>
11 <body>
12  <form method="post" action="http:www.baidu.com">
13        <input>
14        <textarea name="text" cols="20" rows="5" />
15  </form>
16 </body>
17</html>

在此文本框中按enter键,页面会自动跳转到百度的搜索页面。

2:解决方案

  1)去掉form表单。然后在文本框中按enter键就不会出现自动跳转的情况了。(不建议使用)

  2)再添加一个隐藏的文本框。出现问题的原因是form表单中有且只有一个文本框。故新增一个隐藏的文本框也可解决问题。

    <input style="display:none"/>

  3)在表单上添加属性 onsubmit="return false";也可以解决问题。

相关文章

猜你喜欢

学到老在线代码浏览器 关闭浏览
友情链接: hao123 360导航 搜狗网址导航 114啦网址导航 博客大全
Copyright © 1999-2014, WEBKFA.COM, All Rights Reserved  京ICP备14034497号-1