KEYUP不工作的Chrome浏览器在Android [英] keyup not working on Chrome on Android

查看:410
本文介绍了KEYUP不工作的Chrome浏览器在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的引导预输入。

这要看这个jQuery code工作:

It depends on this jQuery code to work:

el.on('keyup', doSomething() )

在Chrome浏览器在Windows上正常工作。在Chrome浏览器在Android事实并非如此。 KeyUp事件永远不会被解雇。其所绝对约束元件具有焦点。

On Chrome on Windows it works fine. On Chrome on Android it doesn't. The keyup event is never fired. The element to which it is bound definitely has the focus.

这似乎是一个新的发展。

This appears to be a recent development.

Chrome浏览器28.0.1500.64 安卓4.1.2 SGP321编译/ 10.1.1.A.1.307

Chrome 28.0.1500.64 Android 4.1.2 SGP321 Build/10.1.1.A.1.307

感谢

- 贾斯汀威利

推荐答案

我碰到同样的问题今天来得早。如何镀铬的android不支持这些关键事件!我假设你已经找到了解决办法了,但在这里就是我想出了现在的修复程序。

I came across this same problem earlier today. How can android chrome not support these key events! I assume you've found a workaround by now, but here's a fix that I came up with for now.

function newKeyUpDown(originalFunction, eventType) {
    return function() {
        if ("ontouchstart" in document.documentElement) { // if it's a touch device, or test here specifically for android chrome
            var $element = $(this), $input = null;
            if (/input/i.test($element.prop('tagName')))
                $input = $element;
            else if ($('input', $element).size() > 0)
                $input = $($('input', $element).get(0));

            if ($input) {
                var currentVal = $input.val(), checkInterval = null;
                $input.focus(function(e) {
                    clearInterval(checkInterval);
                    checkInterval = setInterval(function() {
                        if ($input.val() != currentVal) {
                            var event = jQuery.Event(eventType);
                            currentVal = $input.val();
                            event.which = event.keyCode = (currentVal && currentVal.length > 0) ? currentVal.charCodeAt(currentVal.length - 1) : '';
                            $input.trigger(event);
                        }
                    }, 30);
                });
                $input.blur(function() {
                    clearInterval(checkInterval);
                });
            }
        }
        return originalFunction.apply(this, arguments);
    }
}
$.fn.keyup = newKeyUpDown($.fn.keyup, 'keyup');
$.fn.keydown = newKeyUpDown($.fn.keydown, 'keydown');

这篇关于KEYUP不工作的Chrome浏览器在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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