1
<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>

http://jsfiddle.net/z8KuE/1/

onmouseenter 和 onmouseleave 事件在 Firefox 和 Opera 中正常工作,但显然在 Chrome 中根本不起作用......

像这个小提琴这样的简单基本 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)

4

3 回答 3

1

工作演示

你可以用jquery做到这一点

代码

$('div').mouseenter(function () {
    $(this).css('background', '#aaaaaa');
});
$('div').mouseleave(function () {
    $(this).css('background','#222222');
});
于 2013-09-24T15:29:57.570 回答
0

Did you try this?

<div style="position: relative; left: 50px; top: 30px; width: 300px; height: 150px; background: #222222;" onmouseover="this.style.background='#aaaaaa'" onmouseout="this.style.background='#222222';"></div>

http://jsfiddle.net/z8KuE/2/

于 2013-09-24T15:08:19.877 回答
0

Chrome 仅支持 onmouseover 和 onmouseout

    <div style="position: relative; left: 50px; top: 30px; width: 300px; height: 150px; background: #222222;" 
onmouseenter="this.style.background='#aaaaaa'" 
onmouseleave="this.style.background='#222222';"
onmouseover="this.style.background='#aaaaaa'"
onmouseout="this.style.background='#222222'"

></div>

http://jsfiddle.net/z8KuE/1/

于 2013-09-24T15:08:44.557 回答