本文介紹了jQuery 是否保留觸摸事件屬性?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
雖然此代碼在觸摸屏幕時會產生1"的預期行為:
While this code produces the expected behavior of "1" when touching the screen:
document.getElementById('someNodeId').addEventListener('touchmove', touch, true);
function touch(evt) {
evt.preventDefault();
alert(evt.changedTouches.length);
}
使用 jQuery 選擇器的相同代碼:
the same code using a jQuery selector:
$('#someNodeId').bind('touchmove', touch);
產生錯誤:TypeError: 表達式 'evt.changedTouches'[undefined] 的結果不是對象".
produces the error: "TypeError: Result of expression 'evt.changedTouches'[undefined] is not an object".
(設備 = iPod Touch OS 3.1.3 (7E18);jQuery 1.4.2).
(Device = iPod Touch OS 3.1.3 (7E18); jQuery 1.4.2).
這怎么可能,我做錯了什么?
How is this possible and what am I doing wrong?
推薦答案
試試
$(document).ready (function () {
$("#someNodeId").bind("touchmove", function (event) {
var e = event.originalEvent;
console.log(e.targetTouches[0].pageX);
});
});
這篇關于jQuery 是否保留觸摸事件屬性?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!