标签:
<div id="myDiv"> <input type="button" value="点我" id="myBtn"> </div>
var btn=document.getElementById("myBtn"); btn.onclick=function(){ document.getElementById("myDiv").innerHTML="Progress..."; }
var btn=document.getElementById("myBtn"); btn.onclick=function(){ btn.onclick=null;//移除事件处理程序 document.getElementById("myDiv").innerHTML="Progress..."; }
function eventHandler(e){ //获取事件对象 e = e || window.event;//IE和Chrome下是window.event FF下是e //获取事件源 var target = e.target || e.srcElement;//IE和Chrome下是srcElement FF下是target }
5.取消事件默认行为
function eventHandler(e) { e = e || window.event; // 防止默认行为 if (e.preventDefault) { e.preventDefault();//IE以外 } else { e.returnValue = false;//IE //注意:这个地方是无法用return false代替的 //return false只能取消元素 } }
6.阻止事件冒泡
function myParagraphEventHandler(e) { e = e || window.event; if (e.stopPropagation) { e.stopPropagation();//IE以外 } else { e.cancelBubble = true;//IE } }
html:
<ul id="ulT"> <li class="item1">fsda</li> <li class="item2">ewre</li> <li class="item3">qewe</li> <li class="item4">xvc</li> <li class="item5">134</li> </ul>
js:
document.getElementById("ulT").onclick = function (event) { console.log(event.target); console.log(event.currentTarget); }
标签:
原文地址:http://www.cnblogs.com/mmx-jiayou/p/5047176.html