即使没有SUBMIT按钮,谷歌浏览器也会提交表单 [英] google chrome submits form even if there is no SUBMIT button

查看:280
本文介绍了即使没有SUBMIT按钮,谷歌浏览器也会提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌浏览器中查看时,此页面出现在我的某个页面中,因此我编写了一个测试页,看起来像这样

 <身体GT; 
< form action =loginhandler.php>
< input type =textid =name>
< input type =textid =lastname>
< input type =buttonvalue =登录>
< / form>
< / body>

在这里您可以看到,输入类型不是submit类型。因此,如果您在IE,Firefox,Opera上按ENTER键,则什么都不会发生,这是预期的行为。
但是,如果您在chrome上按Enter,则无论输入类型是否提交,它都会提交。



我的问题是,这是Chrome的默认功能/错误还是我在这里做错了什么。引用HTML5规范的第4.10.21.2节:

解决方案

blockquote>

如果表单没有提交按钮
,那么隐式提交机制
必须从
表单元素本身提交表单元素。表单元素本身。


因此,我认为Chrome的行为是正确的,尽管我认为其他浏览器也这样做,通过听取提交(例如阻止它)事件来阻止/处理表单提交.BlockquoteBlockquotethe form element本身。


This bug/feature cropped up in one of my pages when viewed in google chrome so i wrote a test page which looks like this

<body>
 <form action="loginhandler.php">
      <input type="text" id="name">
      <input type="text" id="lastname">
      <input type="button" value="Login">
 </form>
</body>

Here you can see, the input type is NOT of type submit. So if you press ENTER KEY on IE,Firefox,Opera, nothing happens and that is the expected behavior. But if you press enter on chrome, it SUBMITS regardless of whether the input type is submit or not.

My question , is this a default feature/bug of chrome or am i doing something wrong here. ?

解决方案

To cite section 4.10.21.2 of the HTML5 specification:

"If the form has no submit button, then the implicit submission mechanism must just submit the form element from the form element itself."the form element itself."

Therefore I believe Chrome's behaviour to be correct, although I think other browsers do this as well. You can catch/block/process form submission by listening to the "submit" (e.g. to block it) event.BlockquoteBlockquotethe form element itself."

这篇关于即使没有SUBMIT按钮,谷歌浏览器也会提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆