日期:2014-05-16 浏览次数:20362 次
<div id="div1" style="background:yellow; height:100px; width:100px"></div>
var box=document.getElementById('div1');
function addEvent(el,type,fn){
if(window.addEventListener) {
el.addEventListener(type,fn,false);
}
else if(window.attachEvent) {
el.attachEvent('on'+type,fn);
}
else{
el['on'+type]=fn;
}
}
addEvent(box,'click',f1);
addEvent(box,'click',f2);
function f1(){
alert('here')
alert(this.id)
alert(this)
}
function f2(){
alert('there')
alert(this.id)
alert(this)
}
function addEvent(el,type,fn){
if(window.addEventListener) {
el.addEventListener(type,fn,false);
}
else if(window.attachEvent) {
el.attachEvent('on'+type,function(){
fn.call(el);
});
}
else{
el['on'+type]=fn;
}
}