function bindEvent(elem, type, fn) {
elem.addEventListener(type, fn)
}
var a = document.getElementsByTagName("a");
a.forEach(function(item, index) {
bindEvent(item,"click",function(e){
e.preventDefault();
alert("clicked");
});
})
报错: a.forEach is not a function
a是可以获取的。
登录后可查看更多问答,登录/注册