0

我正在尝试将鼠标悬停事件附加到页面中画廊的所有 img 元素(使用 Mootools)。这很容易使用类似的东西

$$('img.mygalleryclass').addEvents({
mouseover: function(){
    alert(id);
    }
});

我的问题是,如何提醒 $$ 'loop' 中引用的元素的 id?由于未定义 id,因此“alert(id)”每次都会返回错误。

谢谢!

4

1 回答 1

-1

event参数传递给mouseover函数,然后id获取target:

$$('img.mygalleryclass').addEvents({
    mouseover: function(e) {
        alert(e.target.id);
    }
});

这是一个例子。

于 2011-03-11T23:59:43.040 回答