📌  相关文章
📜  javascript 添加监听器到类 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:12.828000             🧑  作者: Mango

代码示例2
var classname = document.getElementsByClassName("classname");

var myFunction = function() {
    var attribute = this.getAttribute("data-myattribute");
    alert(attribute);
};

for (var i = 0; i < classname.length; i++) {
    classname[i].addEventListener('click', myFunction, false);
}