<div style="position: relative; left: 50px; top: 30px; width: 300px; height: 150px; background: #222222;" onmouseenter="this.style.background='#aaaaaa'" onmouseleave="this.style.background='#222222';"></div>
onmouseenter 和 onmouseleave 事件在 Firefox 和 Opera 中正常工作,但显然在 Chrome 中根本不起作用...
像这个 fiddle 一样的简单基本 div 如何在 Chrome 中正常运行,但不更改其内容(除了分配类之外)?
如果可能的话,理想的解决方案是以某种方式为 Chrome 用户注册 onmouseenter 和 onmouseleave 事件,而不分配类。
编辑:我知道 onmouseover 和 onmouseout,但它们是毫无疑问的 - 由于某些实际原因,我需要对我的代码进行一些解决方法。
编辑2:现在我只有一个针对特定类的jquery - http://jsfiddle.net/z8KuE/6/ 。但我有很多 div,其事件已经用 html 编写,位于 <div></div>
内。
例如,我有 2 个像这样的 div ( http://jsfiddle.net/z8KuE/8/ )。想象一下有 200 个 div,并且事件的种类更多。如何以最实用的方式处理这个问题,以便在 Chrome 中使用 jquery 工作? (绝对不会删除200个div的内容并编写200行或更多行的jquery)
最佳答案
工作 DEMO
你可以用 jquery 来做到这一点
代码
$('div').mouseenter(function () {
$(this).css('background', '#aaaaaa');
});
$('div').mouseleave(function () {
$(this).css('background','#222222');
});
关于javascript - 使 onmouseenter 和 onmouseleave 在 chrome 中工作 - html、javascript、jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18985282/