无法获得touchstart事件的属性?

San*_*nam 3 javascript iphone jquery javascript-events

当我尝试实现以下代码时:

$('.touchelement').bind({'touchstart':function(e){
    console.info(e.touches.item(0));
}});
Run Code Online (Sandbox Code Playgroud)

它将输出显示为undefined.不仅在touchstart中,而且对于像touchmove,touchend这样的其他事件,它显示相同的结果.

是否有任何使用jquery绑定touchstart事件的替代方法.

Ric*_*d M 18

jQuery对事件对象进行了一些处理,以使它们在浏览器中保持一致,但它不了解touches数组,因此不会将其复制到新的事件对象中.因此,您需要通过原始事件对象访问它event.originalEvent.

$('.touchelement').bind({'touchstart':function(e){
  console.info(e.originalEvent.touches[0]);
}});
Run Code Online (Sandbox Code Playgroud)