<div class="codetitle"> <span><a style="CURSOR: pointer" data="35047" class="copybut" id="copybut35047" onclick="doCopy('code35047')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code35047"> <br><div id="outer" style="background:#099"> <br>click outer <br><p id="inner" style="background:#9C0">click inner</p> <br><br> <br></div> <br><br><script type="text/javascript"> <br>function G(id){ <br>return document.getElementById(id); <br>} <br>function addEvent(obj, ev, handler){ <br>if(window.attachEvent){ <br>obj.attachEvent("on" ev, handler); <br>}else if(window.addEventListener){ <br>obj.addEventListener(ev, handler, false); <br>} <br>} <br>function test(e){ <br>alert("e.target.tagName : " e.target.tagName "n e.currentTarget.tagName : " e.currentTarget.tagName); <br>} <br>var outer = G("outer"); <br>var inner = G("inner"); <br>//addEvent(inner, "click", test); <br>addEvent(outer, "click", test); <br></script> <br> </div> <br>上面的示例中,当在outer上点击时,e.target与e.currentTarget是一样的,都是div;当在inner上点击时,e.target是p,而e.currentTarget则是div。