gpt4 book ai didi

javascript - 触摸/单击和输入事件监听器不会触发 iOS

转载 作者:行者123 更新时间:2023-11-29 05:33:11 25 4
gpt4 key购买 nike

我有一个应用程序,只是不触发 iOS 上的输入和触摸或单击监听器。我已经研究过这些问题(仅供引用...我使用jQuery):

jQuery click events not working in iOS

jQuery on click not working on iPhone (touch devices)

How do I use jQuery for click event in iPhone web application

还有很多......我学到的内容如下:

  1. 将光标指针添加到元素。 完成。我所有未触发的可点击元素都具有光标:指针的 CSS 属性
  2. 内联点击监听器。 试过了,没有效果
  3. 有点类似...将 onclick=""添加到元素中。 同上,试过了,没有效果
  4. 使用触摸监听器。 试过了,没有效果。这是我即将展示的当前实现。

我知道没有任何东西,比如覆盖元素,因为我已经将 :active 的伪类添加到元素中,只是为了确保 正常工作,并且当我制作可点击元素时积极的,他们按照 CSS 的指示去做。以下是我添加事件监听器的方法:

const interactionEvent = function () {
const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
return iOS ? 'touchstart' : 'click';
};
class SingleLeadInteraction {
constructor() {
const urlSearch = new URLSearchParams(window.location.search);
this.leadId = urlSearch.get("id");
this.addListeners();
}
addListeners() {
this.addNoteButton.addEventListener(interactionEvent(), e => { SingleLeadInteraction.addNoteModal.showModal(); }, false);
this.addAttachmentButton.addEventListener(interactionEvent(), e => { SingleLeadInteraction.addAttachmentModal.showModal(); }, false);
this.changeAgentButton.addEventListener(interactionEvent(), () => { SingleLeadInteraction.changeAgentModal.showModal(); }, false);
const leadDetailInputs = document.querySelectorAll(".field-container label input[data-api-name], .field-container label select[data-api-name]");
leadDetailInputs.forEach(input => {
input.addEventListener("input", e => {
// code that isn't firing
}, false);
});
}
}
SingleLeadInteraction.changeAgentModal = new Modal("#changeAgentModal");
SingleLeadInteraction.addNoteModal = new Modal("#addNoteModal");
SingleLeadInteraction.addAttachmentModal = new Modal("#addAttachmentModal");
let lead;
if (new URL(window.location.href).pathname === "/contact/") {
lead = new SingleLeadInteraction();
}

我一开始只是使用“click”或“touchstart”来调用interactionEvent(),所以我已经尝试过了。

我只是不知道该怎么办。

为什么我的 iOS 事件监听器没有触发?

最佳答案

添加光标:指针;不可点击元素的 CSS 允许点击完全冒泡。

cursor: pointer;

感谢 link description here

https://gravitydept.com/blog/js-click-event-bubbling-on-ios

关于javascript - 触摸/单击和输入事件监听器不会触发 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57334793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com