使用 mootools 选择器访问元素属性

发布于 2024-10-21 17:18:30 字数 244 浏览 10 评论 0原文

我试图将鼠标悬停事件附加到页面中图库的所有 img 元素(使用 Mootools)。使用类似

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

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

谢谢!

I'm trying to attach a mouseover event to all img elements of a gallery in a page (using Mootools). This is easy enough using something like

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

My question is, how do I alert the id of the element referenced in the $$ 'loop'? That "alert(id)" returns an error every time since id is not defined.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吐个泡泡 2024-10-28 17:18:30

event 参数传递给 mouseover 函数,然后获取 targetid

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

这是一个示例。

Pass the event argument to the mouseover function and then get the id of the target:

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

Here's an example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文