jQuery live() removing iPhone touch event attributes?

孤人 提交于 2019-11-29 00:12:43

The touch events are not currently supported by Events/live.

From the documentation:

Possible event values: click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup

Currently not supported: blur, focus, mouseenter, mouseleave, change, submit

You might want to consider trying to use click if that will suit your needs, or you can switch to using livequery, which probably will support it. (livequery is what live was originally based on, I'm not sure why it doesn't support all of the same events)

Actually, you can use the .live method. You don't have the event.touches property because of how jQuery handles events internally. In order to "fix" events, jQuery clones the event. In doing so, it only copies over a limited number of properties for performance reasons. However, you can still access the original event object via the event.originalEvent property.

So your example code would need to look like the following:

$('a').live('touchend', function(event) {
  event.preventDefault();
  console.log(event.originalEvent.touches.length);
});

Here are the properties that are copied over: http://github.com/jquery/jquery/blob/master/src/event.js#L411

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!