无钥匙preSS事件在Android浏览器的某些项钥匙、浏览器、事件、preSS

2023-09-06 02:22:04 作者:人荡无罪 物荡必碎

下面code可以完美运行在Chrome,火狐,在IPhone,甚至在Android上的第三方浏览器。但是,本机浏览器的关键事件的特殊字符,如A,A和O在我的瑞典键盘上运行时根本不会被触发。

Below code works perfect in Chrome, Firefox, on IPhone, and even in third-party browsers on Android. However, when run within the native browser key events for special characters like Å, Ä, and Ö on my Swedish keyboard are simply not triggered.

本示例应仅允许用户在一个时间输入一个字符。工程就像一个魅力,除非我喜欢A,A,O代表,我可以输入任何字符数的Andr​​oid preSS键。

The example should only allow the user to enter a single character at a time. Works like a charm, unless I in android press keys like Å, Ä or Ö for which I can enter any number of characters.

下面是一个的jsfiddle谁愿意尝试一下任何: http://jsfiddle.net/x7H6f/。如果你不具备像我的瑞典那些印在键盘上,像电子字符(按住E)特殊键应该做的绝招。

Here's a jsFiddle for any who wish to try it out: http://jsfiddle.net/x7H6f/. If u don't have special keys like my Swedish ones printed on your keyboard, characters like é (hold E) should do the "trick".

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Key Event test</title>
    </head>
    <body>
        <input type="text" id="a" name="test" />
        <script>
            document.getElementById("a").onkeypress = function(e) {
                e = e || window.event;
                var k = e.keyCode || e.which;
                this.value = String.fromCharCode(k);
                return false;
        }
        </script>
    </body>
</html>

和没有,KeyDown和KEYUP没有擦出火花。我错过了什么,或者这是一个错误?在PhoneGap的瑞典开发的应用程序时,它的可怕烦人!

And no, keydown and keyup don't work either. Did I miss something, or is this a bug? It's horribly annoying when developing Swedish Apps in PhoneGap!

谢谢!

编辑: 由于庄园说,在他的回答中,输入事件可以被使用。这里有一个小提琴这表明之间的键preSS的差异输入变更事件: http://jsfiddle.net/Qxd76/ (使用 http://jsfiddle.net/Qxd76/show 以查看在智能手机上的结果)。

As Manor says in his answer, the input event can be used. Here's a fiddle which demonstrates the differences between the keypress, input, and change events: http://jsfiddle.net/Qxd76/ (use http://jsfiddle.net/Qxd76/show to view the result on a smartphone).

推荐答案

我只花了时间配发的这个问题。我正在开发以希伯来文和希伯来文的所有章程在不触发事件我。

i just spent allot of time about this problem. i'm develop to hebrew and all hebrew charters isn't firing event for me.

我找到了解决办法,我会给它之前

i found the solution and i'll give for it short explain before

在使用的所有重要事件的浏览器搜索你pressing的关键。导致某种原因在其他语言中的所有包机从英语Android原生浏览器是未知的,这是当你填入输入包机,为什么不火的任何事件。

when use all key events the browser search for the key you pressing for. cause some reason all charters in other language from english in android native browser is unknown and this is why isn't fire any event when you fill in input charter.

的解决方案是要搜索的事件在输入和不是该键。例如,如果我们在文本输入.change()方法将是伟大的我们。

the solution is to search for event in the input and not on the key. for example if we have in text input .change() method is will be great for us.

我使用的addEventListener()方法,并正在努力像一个魅力。

i'm using in addEventListener() method and is working like a charm.

这是在code

var exmpleInput = document.getElementById('input-id');
if(exmpleInput) {
    exmpleInput.addEventListener("input", function() {
        exampleFunction(this)
    }, false);
}