【发布时间】:2013-10-17 03:37:57
【问题描述】:
我想获取光标下的元素。当我使用document.querySelectorAll(":hover"); 时,它在 Chrome 中运行良好,但在 Firefox 或 IE 中无法运行。
这可能是因为我在 Google 地图的 eventListener 中使用了它。这里是我如何使用它。
google.maps.event.addListener(polygon,"mouseout",function(){
elementHover = document.querySelectorAll( ":hover" );
alert(elementHover[elementHover.length-1].id);
});
在 Chrome 中,它为我提供了我用光标悬停的元素的 ID,但在 IE 或 FF 中我什么也得不到。
【问题讨论】:
-
在 IE10 和 FF23 中为我工作 --- 测试 setInterval(function(){console.log(document.querySelectorAll(":hover").length);}, 5*1000)跨度>
标签: javascript cross-browser pseudo-class selectors-api