gpt4 book ai didi

javascript - 如何将 onclick 事件附加到元素数组 (mootools)

转载 作者:行者123 更新时间:2023-11-30 09:08:38 25 4
gpt4 key购买 nike

是否有以下内容的语法:

$$('.a-lot-of-elems').addEvent('someevent',somefunction);

最佳答案

首先 - 以下将正常工作。

$$(selector).addEvents({
click: fn
});

不要使用for,要遍历元素集合,请改用each:

$$(selector).each(function(el){
el.addEvents({
click: fn
});
});

这是一个工作示例:http://jsfiddle.net/EPYBx/

关于javascript - 如何将 onclick 事件附加到元素数组 (mootools),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2508185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com