亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

event.currentTarget與event.target的區(qū)別介紹

 更新時(shí)間:2012年12月31日 13:55:16   作者:  
event.currentTarget與event.target的區(qū)別想大家在使用的時(shí)候不是很在意,本文以測(cè)試代碼來(lái)講解它門(mén)之間的不同
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 element on which the event occurred.
即,event.currentTarget指向事件所綁定的元素,而event.target始終指向事件發(fā)生時(shí)的元素。翻譯的不專(zhuān)業(yè),好拗口啊,還是直接上測(cè)試代碼吧:
復(fù)制代碼 代碼如下:

<div id="wrapper">
<a href="#" id="inner">click here!</a>
</div>
<script type="text/javascript" src="source/jquery.js"></script>
<script>
$('#wrapper').click(function(e) {
console.log('#wrapper');
console.log(e.currentTarget);
console.log(e.target);
});
$('#inner').click(function(e) {
console.log('#inner');
console.log(e.currentTarget);
console.log(e.target);
});
/*
以上測(cè)試輸出如下:
當(dāng)點(diǎn)擊click here!時(shí)click會(huì)向上冒泡,輸出如下:
#inner
<a href=​"#" id=​"inner">​click here!​</a>​
<a href=​"#" id=​"inner">​click here!​</a>​
#wrapper
<div id=​"wrapper">​…​</div>​
<a href=​"#" id=​"inner">​click here!​</a>​
當(dāng)點(diǎn)擊click here!時(shí)click會(huì)向上冒泡,輸出如下:
#wrapper
<div id=​"wrapper">​…​</div>​
<div id=​"wrapper">​…​</div>​
*/
</script>

相關(guān)文章

最新評(píng)論