跨浏览器事件的添加与删除

来源:互联网 发布:js怎么使用正则表达式 编辑:程序博客网 时间:2024/06/14 21:53
var webadd={addtings:function(obj,type,hanshu){if(obj.addEventListener){obj.addEventListener(type,hanshu,false);}else if(obj.attachEvent){obj.attachEvent('on'+type,hanshu)}else{obj['on'+type]=hanshu;}},removethings:function(obj,type,hanshu){if(obj.removeEventListener){obj.removeEventListener(type,hanshu,false);}else if(obj.detachEvent){obj.detachEvent('on'+type,hanshu)}else{obj['on'+type]=null;} }}var m=document.getElementById("maomao");webadd.addtings(m,'click',go);function go(){this.style.background='black';}