addEvent 方法

发表于 JS 分类,标签:

全兼容原生绑定事件函数

function  addEvent (ele,type,callback){

if(window.addEventListener){

ele.addEventListener(type, function (event) {

callback(event)

},false);

}else if (window.attachEvent) {

ele.attachEvent('on'+type, function (event) {

callback(event)

});

}else {

ele['on'+type]= function (event) {

callback(event)

}

}

};


0 篇评论

发表我的评论