87,917
社区成员
发帖
与我相关
我的任务
分享
<div id="a">
<div id="aa"></div>
<div id="ab"></div>
<div id="ac"></div>
</div>
function $addEvent(obj,type,handle){
//事件绑定,兼容ff,ie
if (window.addEventListener){
obj.addEventListener(type, handle, false);
}else if (window.attachEvent){
obj.attachEvent("on"+type, handle);
}else{
obj["on" + type] = handle;
}
};
$addEvent(document.getElementById("ab"),"click",function(){alert(this.id)})