标签:优先 remove cti 代码 win child fat false 事件冒泡
addEventListener,removeEventListener
var father = document.getElementById("father"); var fatherHandle = function(event) { console.log(‘--------- father -----------‘) } father.addEventListener("click", fatherHandle, false); father.removeEventListener("click", fatherHandle, false); //有效 father.removeEventListener("click", function(){console.log(‘-- no --‘)}, false); //无效
var father = document.getElementById("father"); var child = document.getElementById("child"); var fatherHandle = function(event) { console.log(‘--------- father -----------‘) } var childHandle = function(event) { console.log(‘--------- child -----------‘) } father.addEventListener("click", fatherHandle, true); child.addEventListener("click", childHandle, true); // father - child
father.addEventListener("click", fatherHandle, false); child.addEventListener("click", childHandle, false); // child - father
调用顺序
<body> <h1 id="father"> father <span id="child" onclick="fun()">child</span> </h1> <script> var child = document.getElementById("child"); var childHandle = function(event) { console.log(‘--------- child -----------‘) } child.addEventListener("click", childHandle, false); var fun = function(e) { console.log(‘--------- property -----------‘) } // property - child </script> </body>
js addEventListener removeEventListener
标签:优先 remove cti 代码 win child fat false 事件冒泡
原文地址:http://www.cnblogs.com/Master-W/p/7367951.html