简体   繁体   English

在移动设备中不执行按钮事件监听器(在 PC 中工作)

[英]Button eventlistener not executing while in Mobile (Works in PC)

After my object is constructed and its value is displayed in an HTML <.li.> A btn is created in another function and returned to be appended to the same <.li.>在构建我的 object 并将其值显示在一个 HTML <.li.> 中之后,在另一个 function 中创建一个 btn 并返回以附加到相同的 <.li.>

The button works fine in desktop but when i swap over to mobile it is very strange.该按钮在桌面上工作正常,但当我切换到移动设备时,它很奇怪。

Sometimes it works, sometimes it doesn't.有时有效,有时无效。

You sometime can't even press the join button (creates object) and you cannot tap on the x button that deletes it.有时您甚至无法按下加入按钮(创建对象),也无法点击删除它的 x 按钮。

But here's the thing, if you scroll around, fidget around a bit and click the buttons again.但事情就是这样,如果你四处滚动,坐立不安,然后再次点击按钮。 There's a chance it will work.它有可能会起作用。

I've tried changing the eventlistener in multiple ways but with no luck.我试过以多种方式更改事件监听器,但没有成功。

I've added console.logs into for every step about what it does so it will be easy to see what I am trying to do when you go through the process with console on the side.我已经为每一步都添加了 console.logs,这样当您 go 通过旁边有控制台的过程时,很容易看到我正在尝试做什么。

Below is the button creation function下面是按钮创建 function

function prepCancelForm(list, i) {

    const cList = document.getElementById("getCancelList");
    const cIndex = document.getElementById("getIndex");
    cList.value = list;
    cIndex.value = i;

    cancelForm.style.display = "";
}

function createBtn(index, listNum) { // creates button
    const btn = document.createElement("button");
    btn.setAttribute("index", index);
    btn.setAttribute("list", listNum);

    btn.addEventListener("pointerdown", (event) => {
        prepCancelForm(btn.getAttribute("list"), btn.getAttribute("index"));
    });

    const bNode = document.createTextNode("X");
    btn.appendChild(bNode);
    return btn;
}

For a bigger insight为了获得更大的洞察力

Here is the live demo - https://lucasynl.github.io/rbc/pages/game.html这是现场演示 - https://lucasynl.github.io/rbc/pages/game.html

Here is the git repo - https://github.com/LucasYNL/rbc这是 git 回购 - https://github.com/LucasYNL/rbc

I've been at this problem for 2 days now and it's driving me nuts.我已经解决这个问题 2 天了,这让我抓狂。 If all this crap will be gone if I just go learn jQuery, let me know.如果我只是 go 学习 jQuery 所有这些废话都会消失,请告诉我。

Ok, so I decided that I didn't need sleep untill I figured this out.好的,所以我决定在弄清楚之前不需要睡觉。 To the point where I started redoing my ENTIRE js files.到了我开始重做整个 js 文件的地步。

Turns out, the code have 0 problems.事实证明,代码有 0 个问题。 It's because my stupid @ss decided to leave the forms (which takes up 80% of mobile screen) dead @ss in the center and anything that is overlapping it is unclick-able.这是因为我愚蠢的@ss 决定让 forms(占据移动屏幕的 80%)死 @ss 在中心,任何与它重叠的东西都无法点击。

So yeah, to solve my own problem, MOVE THE DAMN FORMS.所以,是的,为了解决我自己的问题,MOVE THE DAMN FORMS。

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

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