跨度点击不适用于iPhone/iPad浏览器

发布于 2025-01-27 04:39:37 字数 318 浏览 2 评论 0原文

$(document).on('click', '.span-btn', function(event) {
  event.stopImmediatePropagation();
  if(event.target.id == null || event.target.id.length < 1) return;
  console.log(event.target.id)
});

点击功能在iOS设备浏览器上不起作用。尝试了多种方法 - 接触式,光标:指针和与跨度的绑定。目前,我添加了“ Span-BTN”类的CSS中的光标:指针,以及上述处理单击的代码。

$(document).on('click', '.span-btn', function(event) {
  event.stopImmediatePropagation();
  if(event.target.id == null || event.target.id.length < 1) return;
  console.log(event.target.id)
});

Click function is not working on iOS device browsers. Tried multiple approaches - touchstart, cursor: pointer and binding to the span. Currently, I have added cursor: pointer in the css for the 'span-btn' class and the above code for handling the click.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残花月 2025-02-03 04:39:37

尝试使用iPad和iPhone的touchstart事件。

const userAgent = navigator.userAgent;
event = (userAgent.match(/iPad/i) || userAgent.match(/iPhone/)) ? "touchstart" : "click";

进而

$(document).on(event, '.span-btn', (e) => {...});

Try using touchstart event for iPads and iPhones.

const userAgent = navigator.userAgent;
event = (userAgent.match(/iPad/i) || userAgent.match(/iPhone/)) ? "touchstart" : "click";

and then

$(document).on(event, '.span-btn', (e) => {...});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文