JS事件处理(removeEventListener addEventListener)

<div>detachEvent</div>

1     window.onload = function(){
2       var oDiv = document.getElementById("contentDiv");
3       var func = function(){
4         alert(oDiv.innerHTML);
5       }
6       var funcAlso = function(){
7         alert("also " + oDiv.innerHTML);
8       }
9       //IE
10       if(oDiv.attachEvent){
11         oDiv.attachEvent("onclick",func);
12         oDiv.attachEvent("onclick",funcAlso);
13         //oDiv.detachEvent("onclick",func);
14       } else if(oDiv.addEventListener){
15         //FireFox
16         oDiv.addEventListener("click",func,true);
17         oDiv.addEventListener("click",funcAlso,true);
18         //oDiv.removeEventListener("click",func,true);
19       }
20      
21     }

posted @ 2009-01-16 11:44  T#S  阅读(5228)  评论(2编辑  收藏  举报