简体   繁体   English

触摸/点击和输入事件侦听器不触发 iOS

[英]Touch/Click and input event listeners not firing iOS

I have an application that is just not firing input and touch or click listeners on iOS.我有一个应用程序,它不会在 iOS 上触发输入和触摸或点击侦听器。 I've looked at these questions (just an fyi though...I'm not using jQuery):我看过这些问题(不过仅供参考……我没有使用 jQuery):

jQuery click events not working in iOS jQuery 单击事件在 iOS 中不起作用

jQuery on click not working on iPhone (touch devices) 单击 jQuery 不适用于 iPhone(触摸设备)

How do I use jQuery for click event in iPhone web application 如何在 iPhone Web 应用程序中使用 jQuery 进行单击事件

And so many more..and what I've learned is the following:还有更多……我学到的是以下内容:

  1. Add cursor pointer to the elements.将光标指针添加到元素。 Done.完毕。 All of my clickable elements that aren't firing have the CSS attribute of cursor: pointer on them我所有未触发的可点击元素都具有 cursor: 指针的 CSS 属性
  2. Inline the click listener.内联点击侦听器。 Tried that, to no effect试过了,没有效果
  3. Kind of along the same lines...add onclick="" to the element.有点类似……将 onclick="" 添加到元素。 Same as above, tried that, to no effect同上,试过了,没有效果
  4. Use touch listeners.使用触摸监听器。 Tried that, to no effect.试过了,没有效果。 This is my current implementation that I'm about to show.这是我将要展示的当前实现。

I know there is nothing, like, covering the element because I've added the pseudo class of :active to the elements just to make sure that was working, and when I made the clickable elements active, they did what the CSS told them.我知道没有任何东西,比如,覆盖元素,因为我已经向元素添加了 :active 的伪类,只​​是为了确保正常工作,当我激活可点击元素时,它们会按照 CSS 告诉它们的方式进行。 Here is how I'm adding the event listeners:这是我添加事件侦听器的方法:

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();
}

I first started with just using "click" or "touchstart" where the interactionEvent() calls are, so I've tried that.我一开始只使用“click”或“touchstart”调用interactionEvent(),所以我试过了。

I just don't know what to do.我只是不知道该怎么办。

Why are my iOS event listeners not firing?为什么我的 iOS 事件侦听器没有触发?

Adding cursor: pointer;添加游标:指针; to a non-clickable element's CSS allows clicks to bubble fully.到不可点击元素的 CSS 允许点击完全冒泡。

cursor: pointer;

Thanks to link description here感谢这里的链接描述

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM