jQuery 单击事件未触发 - ios 主屏幕 Web 应用程序

标签 jquery ios events web-applications click

构建 Web 应用程序时无法触发点击事件。从普通的 Safari 实例运行时,它运行完美,但从主屏幕运行时,它会失败。

$("a.applink").live('click', clickHandler);
var clickHandler = function(e) {
    console.log(e);
    e.preventDefault();
}

从主屏幕运行时,“e”为空。如果我用“touchend”替换“click”,它确实有效,但 touchend 没有给出正确的行为(即,如果您碰巧触摸一个链接开始滚动,它会触发意外点击)。

是否有合适的解决方案?

最佳答案

这是我的做法:

本质上,当您浏览页面时,您需要点击或滚动。 (好吧,还有其他的东西,比如捏和滑动,你可以稍后再弄清楚)......

所以在点击你的“touchstart”之后将是一个“touchend” 在滚动条上,您的“touchstart”后跟一个“touchmove”

使用 Jq 1.7...在其他版本上你可以使用 .bind()

function nextEvent() {
    //behaviour for end
    $(this).on('touchend', function(e){
        /* DO STUFF */
        $(this).off('touchend');
        });
    //behaviour for move
    $(this).on('touchmove', function(e){
        $(this).off('touchend');
        });     
    }

$(element).on('touchstart', this, nextEvent);

基本上,当“touchstart”发生时,我将 Action 绑定(bind)到“touchend”和“touchmove”。

'Touchend' 做任何我想让点击做的事,然后自行解除绑定(bind) 'Touchmove' 除了取消绑定(bind) 'touchend' 基本上什么都不做

这样,如果你点击你就会得到 Action ,如果你滚动除了滚动什么都不会发生..

关于jQuery 单击事件未触发 - ios 主屏幕 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12218883/

相关文章:

javascript - jquery和ajax删除构造框

jqueryui datepicker,比较两个日期并调整大于或小于

jquery - Fancybox 3 无法覆盖 iframe 的宽度和高度

objective-c - 为什么-[NSString stringWithFormat :] don't need a nil to indicate the end of arguments?

.net - 当用户单击 X(关闭程序)时,VB.NET 重载默认功能

javascript - 打开新标签页

javascript - 选择 sibling 的文本

ios - 快速获取错误 : "Missing Argument for Parameter ‘frame’ in call"的核心图

ios - 单击按钮显示下一个/上一个日期

jQuery html() 方法在交换后取消绑定(bind)事件到内部 html 内的元素?