javascript模拟jQuery封装委托事件,兼容IE


 var $ = function(id){
var dom = document.getElementById(id);
return {
on:function(eventType,element,callback){
if(document.addEventListener){
dom.addEventListener(eventType,function(e){
var ev = e || window.event;
var target = ev.target || ev.srcElement
if(target.tagName.toLowerCase()===element){
callback.call(target,ev);
}
},false);
}else{
//兼容IE浏览器
document.attachEvent("on"+eventType,function(e){
var ev = e || window.event;
var target = ev.target || ev.srcElement
if(target.tagName.toLowerCase()===element){
callback.call(target,ev);
}
});
}
}
}
};


上一篇:简单的背包变形HDU1203,HDU2955


下一篇:屏幕适配1(Android 增强版百分比布局库 为了适配而扩展)