2013-10-01 18 views
1

我喜touchmove事件記錄,爲什麼touchmove僅可使用

這個代碼不爲我工作,

$(".tempClass").on("touchmove",function(){ 
    alert("touchmove on div"); 
}); 

此代碼爲我工作,

$(document).on("touchmove",function(){ 
    alert("touchmove on document"); 
}); 

我的關注爲什麼我不能在div元素上聽touchmove

我使用phonegap 3.0,android 4.0.4。

設備上我測試是三星Galaxy Tab 10.1

回答

2

一般來說,事件委派時使用,我們不知道什麼時候一個元素將在DOM存在。它依賴於事件冒泡DOM直到他們到達根選擇(在你的情況下它總是文檔元素)。

$(document).on('touchmove', '.tempClass', function() { 
    // ... 
}); 
相關問題