which與target
請(qǐng)問下原文的which和target分別的用法和意義。。
?$("button:eq(0)").mousedown(function(e) {
? ? ? ? alert('e.which: ' + e.which)
? ? })
$('p').mousedown(function(e) {
? ? ? ? ? ? alert(e.target.textContent)
? ? ? ? })
? ? ? ? //this指向button元素
? ? $("button:eq(1)").mousedown(function() {
? ? ? ? $('p').mousedown() //指定觸發(fā)綁定的事件
? ? })
2017-07-21
which是event事件的一個(gè)標(biāo)志屬性,一般用來(lái)區(qū)分鼠標(biāo)左鍵右鍵,target是事件產(chǎn)生的對(duì)象,上文中target指p元素節(jié)點(diǎn)對(duì)象。
2017-08-28
event.target代表的是觸發(fā)事件的dom對(duì)象,是靜態(tài)不變的。
.this是事件冒泡,動(dòng)態(tài)變化。先觸發(fā)內(nèi)部事件,由內(nèi)到外的執(zhí)行。
兩者都代表dom對(duì)象,如果需要調(diào)用jquery的方法可以這樣$(this),$(event.target)。