将带有ASCII控制字符的条形码扫描到输入字段中 [英] Scanning a barcode with an ASCII control character into an input field

查看:430
本文介绍了将带有ASCII控制字符的条形码扫描到输入字段中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 ASCII 29(分组分隔符)扫描条形码到HTML输入字段,并用|替换所有组分隔符。当我第一次扫描条形码到 Notepad ++ 时,下列JavaScript函数可以工作,然后复制它到输入字段,而不是当条形码直接扫描到输入字段时。问题是什么?

  var barcode = document.getElementById('barcode')。value; 
barcode = barcode.replace(new RegExp(String.fromCharCode(29),'g'),'|');
alert(barcode);在我的Symbol Tech条形码扫描仪上,字符被发送为:击键。例如,组分隔符将模拟按住left_control键然后发送右括号。您的浏览器将处理模拟的按键,就好像您尝试使用 CTRL + ] 作为快捷方式一样。

您可以使用 onkeydown 和event.of来捕获此事件,如下所述:
Firefox onkeydown检测按键


I need to scan a barcode with ASCII 29 (group separator) into an HTML input field, and replace all the group separators with |. The following JavaScript function works when I first scan the barcode into Notepad++ and then copy it to the input field, but not when the barcode is scanned directly into the input field. What's the problem?

var barcode = document.getElementById('barcode').value;
barcode = barcode.replace(new RegExp(String.fromCharCode(29), 'g'), '|');
alert(barcode);

解决方案

On my Symbol Tech barcode scanner, characters are sent as key strokes. For example, the group separator will emulate holding down the left_control key and then sending a right bracket. Your browser will handle the simulated key strokes as if you were trying to use CTRL+] as a shortcut.

You can capture this event with onkeydown and event.which as described here: Firefox onkeydown detect pressed key

这篇关于将带有ASCII控制字符的条形码扫描到输入字段中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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