event.currentTarget identifies the current target for the event, as the event traverses the DOM. It always refers to the element the event handler has been attached to as opposed to event.target which identifies the elelement on which the eventopposed to event.target which.即,event.currentTarget指向事件所綁定的元素,而event.target則是始終指向事件發生時的元素。翻譯的不專業,好拗口啊,還是直接上測試代碼吧:
<script> <BR>$('#wrapper').click(function(e) { <BR>console.log(' #wrapper'); <BR>console.log(e.currentTarget); <BR>console.log(e.target); <BR>}); <BR>$('#inner').click(function( e) { <BR>console.log('#inner'); <BR>console.log(e.currentTarget); <BR>console.log(e.target); <BR>}); <BR>/ * <BR>以上測試輸出如下: <BR>點擊click here!時click會向上冒泡,輸出如下: <BR>#inner <BR><a href="#" id="inner"> click here! <BR><a href="#" id="inner">click here! <BR>#wrapper <BR><div id= "wrapper">…</script>
click here! 點擊click here!時click會向上冒泡,輸出如下:
#wrapper
…
…
*/