ie下如果您在text输入框按回车就会默认将表单提交,可是俺万万没有想到,竟然强大到连submit的onclick事件都能触发了…

示例1:input外面有form标签,输入框按回车会提交表单

<html>
<body>
<form action="http://g.cn">
    <input type="submit" value="haha" onclick="alert(1);" />
    <input  type="text" />
</form>
</body>
</html>
Copy Code | Run Code

示例2:input外面没有form标签,输入框按回车会触发submit的onclick事件

<html>
<body>
<input type="submit" value="haha" onclick="alert(1);" />
<input  type="text" />
</body>
</html>
Copy Code | Run Code

ajax提交流行的今天,form标签往往直接被省略,所以这个特性很可能造成用户在某个输入框按了回车,然后某处一个不相关的button被ie点了一下….