Javascript点击不在手机上工作

时间:2022-06-28 01:23:52

I have a javascript function that works fine on PC, but it doesn't work when loaded on mobile. I think it is because mobile treats tap and click differently, but how do I modify the following function so that it works on mobile? Thank you.

我有一个在PC上运行良好的javascript函数,但在移动设备上加载时它不起作用。我认为这是因为移动设备点击并点击不同,但如何修改以下功能以便它可以在移动设备上运行?谢谢。

(function () {
    var a = { 48: "0", 49: "1", 50: "2", 51: "3", 52: "4", 53: "5", 54: "6", 55: "7", 56: "8", 57: "9", 96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6", 103: "7", 104: "8", 105: "9", 106: "x", 107: "+", 109: "-", 110: ".", 111: "\u00f7", 8: "backspace", 13: "=", 46: "c", 67: "c" }, b = function (b) {
        if (b.keyCode in a) {
            var c = document.getElementById("button-" + a[b.keyCode]);
            c.className.match(/(\s|^)active(\s|$)/) || (c.className += " active");
            setTimeout(function () {
                c.className.match(/(\s|^)active(\s|$)/) && (c.className = c.className.replace(/(\s|^)active(\s|$)/, " "))
            }, 100);
            document.createEvent ? (b = document.createEvent("HTMLEvents"), b.initEvent("click", !0, !0), c.dispatchEvent(b)) : (b = document.createEventObject(), c.fireEvent("onclick", b))
        }
    };
    document.addEventListener ? document.addEventListener("keyup", b, !1) : document.attachEvent && document.attachEvent("keyup", b)
})();

1 个解决方案

#1


0  

As seen in the link below, add touchstart to your initEvent and/or fireEvent function calls.

如下面的链接所示,将touchstart添加到initEvent和/或fireEvent函数调用中。

https://*.com/a/22015946/3042383

https://*.com/a/22015946/3042383

#1


0  

As seen in the link below, add touchstart to your initEvent and/or fireEvent function calls.

如下面的链接所示,将touchstart添加到initEvent和/或fireEvent函数调用中。

https://*.com/a/22015946/3042383

https://*.com/a/22015946/3042383