读书人

IE上option的onclick事件

发布时间: 2012-11-01 11:11:32 作者: rapoo

IE下option的onclick事件

最近在实现一个小功能时碰到了问题:想让用户通过点击一个下拉列表来打开一个新窗口。下面是简单的代码示例:

?? 
以上的思想来自于:
Remove the events from the options, use an event directly on the select instead.

Internet Explorer treats select boxes slightly different than therest of the document, (if you've ever read anyhting about "windowedcontrolls" you know what I'm talking about)

I'm thinking IE doesn't notice events in childnodes of select elements, only the select elements themselves.

I normally setup my functions to work depending on either of the selects value or selectedIndex attribute & using the onchange event.


PS:
虽然onchange在某些时刻可以代替 option的click事件, 但是两者并无法做到完全等价. 因为onchange只有在 你点击的option和之前的option不同时才会触发. 当select当前选中的是第一项 而你再次点击第一项时, select是不会被触发的. 下面的代码演示了一种间接实现 option onclick的方法 注意:此方案只适用于下拉方式的单选select.

以上补充说明来自http://www.cnblogs.com/interdrp/archive/2009/08/03/1537930.html

读书人网 >Web前端

热点推荐