Sea*_* N. 2 javascript jquery bluetooth ipad ios
我遇到麻烦keyup(),keydown()而keypress()事件在iPad上运行.当我连接无线蓝牙键盘并尝试使用键盘输入时会出现问题 - 事件不会触发.我尝试在iPad上使用Safari和Chrome(iOS 6.1).这个相同的HTML在桌面上的Firefox,Safari,Chrome等中运行良好.有没有办法更改此代码,使其在平板电脑上工作?我检查了document.activeElement,它似乎是文件正文,这是正确的.
<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>
Run Code Online (Sandbox Code Playgroud)
显然在iOS上,除非文本字段具有焦点,周期,否则键盘将无法工作.
要解决这个问题,我需要在HTML中添加隐藏文本字段.像这样的东西:
<div style="overflow: hidden; position: relative; width: 1px; height: 1px; left: -500px">
<input id="input" type="textfield" autocorrect="off" autocapitalize="off">
</div>
Run Code Online (Sandbox Code Playgroud)
现在的问题是,JavaScript无法在iPad上自动提供隐藏的输入焦点.因此,我将不得不添加某种必须物理点击的按钮,以提供隐藏的输入字段焦点.看到这里.
<input type="button" value="Click here first" onclick="document.getElementById('input').focus();">
Run Code Online (Sandbox Code Playgroud)
我讨厌这个.如果有人能找到更好的解决方案,请告诉我.
| 归档时间: |
|
| 查看次数: |
14905 次 |
| 最近记录: |