MC_*_*a_T 8 javascript forms submit internet-explorer-10
抱歉标题,我知道它凌乱,但我不知道我怎么能描述这种情况.
我们有一个输入字段.但没有形式元素.这是代码
<input name="search" id="search" onkeypress="SearchBox(this.value);" type="text" value="Search"/>
<input name="searchbutton" align="left" class="okbutton" id="searchbutton" onclick="SearchBox(search.value);" type="button"/>
Run Code Online (Sandbox Code Playgroud)
SearchBox函数检查keycode,如果是13(输入按钮charcode)发送搜索请求.此代码适用于IE8/9,但在IE10中有一些有趣的行为.
上面的代码页面中间.我们在LOGIN的页面顶部有一个按钮元素.
在IE10中;
我在输入中输入一个单词并按回车键:
注意:抱歉语言,英语不是我的母语.注2:删除了SearchBox()函数.检查jsfiddle链接以获取最新代码.
MC_*_*a_T 18
另一种方案
将按钮类型定义为按钮.因为默认类型是提交
<button type="button" ....
Run Code Online (Sandbox Code Playgroud)