如何添加 Javascript 侦听器以捕获从蓝牙条码扫描器到 iPad 的输入?

How can I add a Javascript listener to capture input from bluetooth barcode scanner to iPad?(如何添加 Javascript 侦听器以捕获从蓝牙条码扫描器到 iPad 的输入?)
本文介绍了如何添加 Javascript 侦听器以捕获从蓝牙条码扫描器到 iPad 的输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 iPad 上用 JavaScript 记录击键时遇到问题.以下脚本适用于 Chrome 和 Safari,但不适用于 iPad Safari.蓝牙条码扫描器发送 12 位数字作为按键,然后发送一个返回字符.有人有什么想法吗?

I'm having trouble logging keystrokes in javascript on the iPad. The following script works on Chrome and Safari, but not iPad Safari. The bluetooth barcode scanner sends 12 digits as keystrokes, then sends a return character. Does anyone have any ideas?

我想你需要一个 iPad 来试试这个 :)

I think you will need an iPad to try this out :)

谢谢,标记

$(document).ready(function(){
 $(document).keypress(function(e){
  if( e.keyCode == 13){
   alert($('#barcode').attr('value'));
   $('#barcode').attr('value','');
  }
  else{
   var key = String.fromCharCode(e.which);
   var new_val = $('#barcode').attr('value') + key;
   $('#barcode').attr('value',new_val);
  }
 });
});

推荐答案

iOS 版 Safari 不会在非表单组件的 DOM 元素上触发键盘事件.这包括通常用于捕获页面上任何位置的击键的文档和正文.

Safari for iOS doesn't trigger keyboard events on DOM elements that are not components of a form. This includes the document and body which are usually used to capture keystrokes anywhere on the page.

在文档或页面正文上触发击键事件的唯一方法是在输入或文本区域中触发它.在这种情况下,事件将正确地冒泡"到正文和文档.

The only way to trigger a keystroke event on document or body of a page is to trigger it in an input or textarea. In that case, the event will correctly 'bubble' to the body and document.

但是,这可能是一个问题,因为 iOS 版 Safari 不允许我们从 javascript 中提供元素焦点.

However, this might be a problem because Safari for iOS doesn't allow us to give an element focus from javascript.

目前,我们使用的解决方案是用户必须在开始第一次扫描之前点击输入字段,然后输入字段移出屏幕但保持焦点.

At the moment, we are using a solution where user has to click on an input field before starting the first scan, and the input field is then moved off-screen but retains focus.

如果有人有更好的解决方案,请分享.

If someone has a better solution, please share.

这篇关于如何添加 Javascript 侦听器以捕获从蓝牙条码扫描器到 iPad 的输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)