【问题标题】:Touchstart click event is not working for iPhone / iPadeTouchstart 点击事件不适用于 iPhone / iPade
【发布时间】:2021-07-27 22:51:50
【问题描述】:

我已经编写了一个事件来通过 jQuery 打开新的浏览器选项卡 (window.open),如下所示:

$(document).on('touchstart click', '.myClass', {self: this}, function (e) {

    var mylink = e.data.self.validateDomValue(this, 'attr=data-affiliate')

    if(myLink)
    {
        window.open(mylink, '_blank');
    }
});

此脚本在 windows、mac 和 iPad 上运行良好,但在 iPhone 上出现了问题。该事件未针对 iPhone(版本:5、6 和 7)触发。我的错误是什么?您的任何建议将不胜感激。

【问题讨论】:

    标签: jquery iphone click window.open touchstart


    【解决方案1】:

    哦!是的!我明白了。我需要使用 css cursor:pointer。这对我有用。

    if (/iP(hone|od|ad)/.test(navigator.platform)) 
    {
        $(".myClass").css({"cursor":"pointer"});
    }
    

    【讨论】:

      【解决方案2】:

      一旦我使用的元素位于“位置:固定”上,使用 css 光标:指针对我不起作用。 我添加了一个“点击”事件监听器,它解决了这个问题。 单击元素后,只会触发其中一个事件。

      【讨论】:

      • 您好,欢迎来到 StackOverflow!请添加更多细节。在 iOS/Safari 的哪些版本中,之前的答案不起作用?
      猜你喜欢
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-12
      • 2011-12-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多