扩展 jQuery 的 .on() 以处理移动触摸事件 [英] Extend jQuery's .on() to work with mobile touch events
问题描述
我正在尝试使用 jQuery mobile 事件而不使用 jQuery mobile 的其余部分.
I am attempting to use the jQuery mobile events without the rest of jQuery mobile.
https://github.com/jvduf/jquery-mobile-events/blob/master/jquery.mobile.events.js
该代码段启用了它们,并且工作正常,但不适用于 .on() 事件处理程序.例如:
That snippet enables them all, and works fine, but not with the .on() event handler. E.g:
$('a').on('tap',function(){
console.log('Hi there!');
});
不过它确实适用于 .live(),但现在已经折旧了.
However it does work with .live(), but that is now depreciated.
所以我的问题;有没有办法扩展 .on() 功能以包括点击事件和其他事件?完整列表如下:
So my question; is there a a way to extend the .on() functionality to include the tap event and others? Full list below:
- 触摸启动
- 触摸移动
- 触摸结束
- 方向改变
- 点按
- 点按
- 滑动
- 向左滑动
- 向右滑动
- 滚动开始
- 滚动停止
谢谢:)
推荐答案
不过它确实适用于 .live(),但现在已经折旧了.
However it does work with .live(), but that is now depreciated.
所以我认为您想使用事件委托来保留替换元素上的这些事件.这意味着:
So I take it that you want to use event delegation to preserve those events on replaced elements. That would mean that this:
$('a').on('tap',function () {
console.log('Hi there!');
});
需要更改为:
$(document).on('tap', 'a', function () {
console.log('Hi there!');
});
为了让它的行为与 $("a").live("tap", ...
这篇关于扩展 jQuery 的 .on() 以处理移动触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!