我正在尝试这样,它不适用于iPhone
$(document).bind('touchstart',function(){
alert('hello');
});
Run Code Online (Sandbox Code Playgroud)
但它的工作方式如下
document.addEventListener('touchstart', function(){
alert('hello');
}, false);
Run Code Online (Sandbox Code Playgroud)
如何使用jquery获取touchstart事件?
它的工作
$(document).on('touchstart', function(e){
//e.preventDefault();
var touch = e.touches[0] || e.changedTouches[0];
});
Run Code Online (Sandbox Code Playgroud)
但是获取错误e.touches不是一个对象
bjo*_*rnd 11
要获取touches属性,您可以使用e.originalEvent:
$(document).on('touchstart', function(e){
var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
});
Run Code Online (Sandbox Code Playgroud)