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 }
作者:Olar Tan
出处:http://www.cnblogs.com/olartan
♪:没有做不到的 只有偷懒而错过的 ♪