IE and Chrome don't fire a mouseover event for <option> elements

匿名 (未验证) 提交于 2019-12-03 02:03:01

问题:

My code only works in Firefox. Why is this?

HTML:

Javascript:

$(function() {    $(document).on("mouseover", "#selecter option",function(){             alert(1)             }); });

I'm curious why IE and chrome don't fire a mouseover event. See this JSFiddle: http://jsfiddle.net/yT6Y5/72/ (Works perfectly in Firefox.)

How can I get IE and Chrome to fire a mouseover event?

回答1:

The problem is that browsers render dropdowns differently. Chrome is rendering it not as an HTML component but as a native GUI one. That can't have hover handlers associated to it from JS.

If you want to make sure it works on all browsers either don't use a dropdown or get a script to create a dropdown that uses HTML elements



回答2:

It seems, no events are actually fired when you hover over an option in IE & chrome,

At best should should bind on the change event.

$(function() {     $("#selecter").change(function(){             alert(1);     }); });


回答3:

maybe you should use , a different approach to bind the event

 $(function() {     $("#selecter").mouseover(function(){         alert(1)              });   });


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