<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。