当我尝试执行以下代码时:
$('.touchelement').bind({'touchstart':function(e){
console.info(e.touches.item(0));
}});
它将输出显示为未定义。不仅在 touchstart
中,对于其他所有事件(touchmove
、touchend
),它都显示相同的结果。
是否有其他方法可以使用 jQuery 绑定(bind) touchstart
事件。
最佳答案
jQuery 对事件对象做了一些处理,使它们在浏览器中保持一致,但它不知道 touches
数组,因此不会将其复制到新的事件对象。因此,您需要通过原始事件对象访问它,即 event.originalEvent
。
$('.touchelement').bind({'touchstart':function(e){
console.info(e.originalEvent.touches[0]);
}});
关于javascript - 无法获取 touchstart 事件的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6173382/