Javascript点击不在手机上工作

时间:2017-08-23 17:16:14

标签: javascript html5 jquery-mobile mobile javascript-events

我有一个在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 个答案:

答案 0 :(得分:1)

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

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