开发者

Order of onclick and onselect Javascript events

When a user clicks on a select control to select an o开发者_如何学编程ption, do both the onclick and onselect events fire? If so, in what order? Is it browser-dependent?


The select event does not do what you think it does. It fires when you select text within a textbox or textarea. The events that fire when you click on a select element are:

  1. mousedown
  2. focus (if the select element did not already have focus)
  3. mouseup
  4. click

When you change the selected value by clicking on an item in the select list, the change event is fired. In IE, this event is also fired every time you change the highlighted item with the keyboard. In Firefox and Chrome, you have to hit the 'enter' key to trigger change.


Should be fairly easy to test:

<select onclick="alert('click');" onselect="alert('select');"><option>A</option><option>B</option></select>


It should be:

  • mousedown
  • mouseup
  • click
  • select

But I'm not sure if nonstandard browsers (IE) always conform to this. If in doubt, test it with a bunch of event listeners.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜