which與target
請問下原文的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() //指定觸發綁定的事件
? ? })
2017-07-21
which是event事件的一個標志屬性,一般用來區分鼠標左鍵右鍵,target是事件產生的對象,上文中target指p元素節點對象。
2017-08-28
event.target代表的是觸發事件的dom對象,是靜態不變的。
.this是事件冒泡,動態變化。先觸發內部事件,由內到外的執行。
兩者都代表dom對象,如果需要調用jquery的方法可以這樣$(this),$(event.target)。