IE10 find first button on page and trigger click event on input submit

扶醉桌前 提交于 2019-12-19 06:01:12

问题


sorry about title, i know its messy but i dont know how can i describe this situation.

we have an input field. but no form element. here is the code

<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"/>

SearchBox function checking keycode and if it is 13 (enter button charcode) sending search request. this code works in IE8/9 but in IE10 have interesting behaviour.

above code middle of the page. and we have a button element top of the page for LOGIN.

in IE10;

i enter a word in input and press enter:

  • SearchBox function work,
  • but behave like LOGIN button is clicked also and its a problem

note:sorry about language, english is not my native language. note 2: SearchBox() function removed. check the jsfiddle link for the latest code.


回答1:


another solution

define your buttons type as button. because default type is submit

<button type="button" ....



回答2:


Well, IE10 for Windows7 is a pre-release, and this seems to be one of the things MS should fix. Anyway, I don't know why this happens, but I've found a workaround for the problem:

Instead of button, use <input type="button">.

Live demo at jsFiddle.




回答3:


I was having the same problem. Adding type="button" to all my buttons worked. <button type="button">...

Even though my buttons are not in a form.

From other testing I've done IE 10 works exactly like Chrome. This is the only exception I've seen.



来源:https://stackoverflow.com/questions/13497606/ie10-find-first-button-on-page-and-trigger-click-event-on-input-submit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!