[英]Button eventlistener not executing while in Mobile (Works in PC)
在构建我的 object 并将其值显示在一个 HTML <.li.> 中之后,在另一个 function 中创建一个 btn 并返回以附加到相同的 <.li.>
该按钮在桌面上工作正常,但当我切换到移动设备时,它很奇怪。
有时有效,有时无效。
有时您甚至无法按下加入按钮(创建对象),也无法点击删除它的 x 按钮。
但事情就是这样,如果你四处滚动,坐立不安,然后再次点击按钮。 它有可能会起作用。
我试过以多种方式更改事件监听器,但没有成功。
我已经为每一步都添加了 console.logs,这样当您 go 通过旁边有控制台的过程时,很容易看到我正在尝试做什么。
下面是按钮创建 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;
}
为了获得更大的洞察力
这是现场演示 - https://lucasynl.github.io/rbc/pages/game.html
这是 git 回购 - https://github.com/LucasYNL/rbc
我已经解决这个问题 2 天了,这让我抓狂。 如果我只是 go 学习 jQuery 所有这些废话都会消失,请告诉我。
好的,所以我决定在弄清楚之前不需要睡觉。 到了我开始重做整个 js 文件的地步。
事实证明,代码有 0 个问题。 这是因为我愚蠢的@ss 决定让 forms(占据移动屏幕的 80%)死 @ss 在中心,任何与它重叠的东西都无法点击。
所以,是的,为了解决我自己的问题,MOVE THE DAMN FORMS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.