移动设备上的Java单击事件 [英] Javascript click event on mobile

查看:56
本文介绍了移动设备上的Java单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Javascript函数,可以在PC上正常工作,但是在移动设备上加载时不起作用.我认为这是因为移动设备对点击和点击的处理不同,但是如何修改以下功能,使其可以在移动设备上使用?

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?

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

推荐答案

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

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

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

这篇关于移动设备上的Java单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆