JQuery的KEYUP()的keydown()和重点$ P $(PSS)不与iPad和蓝牙键盘工作 [英] JQuery keyup() keydown() and keypress() are not working with iPad and bluetooth keyboard

查看:246
本文介绍了JQuery的KEYUP()的keydown()和重点$ P $(PSS)不与iPad和蓝牙键盘工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不在iPad上运行麻烦的KEYUP()的keydown()和重点preSS()事件。事件不火 - 当我有一个无线蓝牙键盘连接并使用键盘打字试试出现麻烦。我试着用Safari和Chrome浏览器在iPad(iOS版6.1)。同样的HTML工作正常火狐,Safari,Chrome浏览器等桌面上。有什么办法来改变这种code,使其在平板电脑上运行?我检查document.activeElement,它似乎是文档的身体,这是正确的。

 < HTML和GT;
    < HEAD>
        &LT;脚本的src =// ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js\"></script>
        &LT;脚本&GT;
            $(文件)。就绪(函数(){
                (文档)$ .keyup(函数(事件){
                    。的document.getElementById(产出)的innerHTML =的document.getElementById(输出)的innerHTML +(KEYUP+ event.which)+&LT; BR&gt;中;
                });
                (文档)$ .keydown(函数(事件){
                    。的document.getElementById(产出)的innerHTML =的document.getElementById(输出)的innerHTML +(的keydown+ event.which)+&LT; BR&gt;中;
                });
                (文档)$ .KEY preSS(函数(事件){
                    的document.getElementById(产出)的innerHTML =的document.getElementById(输出)的innerHTML +(键preSS+ event.which)+。&LT; BR&gt;中;
                });
            });
        &LT; / SCRIPT&GT;
    &LT; /头&GT;
    &LT;身体GT;
        &LT; D​​IV ID =输出&GT;&LT; / DIV&GT;
    &LT; /身体GT;
&LT; / HTML&GT;


解决方案

显然好了iOS上,键盘不会工作,除非文本字段具有焦点,时期。结果
要解决这个问题,我将需要隐藏的文本字段添加到HTML。事情是这样的:

 &LT; D​​IV的风格=溢出:隐藏;位置:相对;宽度:1px的;身高:1px的;左:-500px&GT;
&LT;输入ID =输入类型=文本框自动更正=关闭autocapitalize =关&GT;
&LT; / DIV&GT;

现在的问题是,没有在JavaScript中没有办法在iPad自动给隐藏的输入焦点。所以我不得不添加某种按钮具有在物理上点击给隐藏的输入字段的焦点。请参见 href=\"http://stackoverflow.com/questions/5978470/ipad-html-focus\">。

 &LT;输入类型=按钮值=点击这里第一的onclick =的document.getElementById('输入')专注();&GT;

我讨厌这一点。如果任何人都可以找到一个更好的解决方案,请让我知道。

I'm having trouble getting the keyup(), keydown() and keypress() events to work on an iPad. The trouble occurs when I have a wireless bluetooth keyboard connected and try typing using the keyboard -- the events do not fire. I tried with both Safari and Chrome on the iPad (iOS 6.1). This same HTML works fine in Firefox, Safari, Chrome, etc on the desktop. Is there any way to change this code to make it work on the tablet? I checked document.activeElement, and it seems to be the document body, which is correct.

<html>
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script>
            $(document).ready(function() {
                $(document).keyup(function(event) {
                    document.getElementById("output").innerHTML = document.getElementById("output").innerHTML + ("keyup " + event.which) + "<br>";
                });
                $(document).keydown(function(event) {
                    document.getElementById("output").innerHTML = document.getElementById("output").innerHTML + ("keydown " + event.which) + "<br>";
                });
                $(document).keypress(function(event) {
                    document.getElementById("output").innerHTML = document.getElementById("output").innerHTML + ("keypress " + event.which) + "<br>";
                });
            });
        </script>
    </head>
    <body>
        <div id="output"></div>
    </body>
</html>

解决方案

Well apparently on iOS, the keyboard will not work unless a text field has focus, period.
To work around this, I'm going to need to add a hidden text field to the HTML. Something like this:

<div style="overflow: hidden; position: relative; width: 1px; height: 1px; left: -500px">
<input id="input" type="textfield" autocorrect="off" autocapitalize="off">
</div>

Now the problem is, there is no way in JavaScript to give the hidden input focus automatically on an iPad. So I'm going to have to add some sort of button that has to be physically clicked on to give the hidden input field focus. See here.

<input type="button" value="Click here first" onclick="document.getElementById('input').focus();">

I hate this. If anyone can find a better solution, please let me know.

这篇关于JQuery的KEYUP()的keydown()和重点$ P $(PSS)不与iPad和蓝牙键盘工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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