简体   繁体   English

键盘输入与条形码输入

[英]Keyboard input vs Barcode Input

I have a textbox that shows only numbers 我有一个仅显示数字的文本框

    <input type="number" min="0" max="999999999999999999" maxlength="1">

and I have a barcode scanner 我有条码扫描器

now 现在

the thins is that when I type on my keyboard I can only type 1 character and it will show 1 character on the textbox but I am having trouble in the barcode scanner because when I scan on the scanner it only shows 1 character on the text box and I need the whole barcode 缺点是,当我在键盘上打字时,我只能键入1个字符,并且它将在文本框中显示1个字符,但是我在条形码扫描仪中遇到了麻烦,因为在扫描仪上进行扫描时,它在文本框中仅显示1个字符我需要整个条形码

can someone please help me on the codes 有人可以在代码上帮我吗

*note: there should only be one textbox *注意:只能有一个文本框

you've set the maxlength of the input to maxlength="1" - which means that this input can't have more than 1 character - not matter if the source is keyboard or barcode scanner (barcode scanner eventually emulates keyboard input). 您已将输入的最大长度设置为maxlength =“ 1”-表示此输入不能超过1个字符-不管源是键盘还是条形码扫描仪(条形码扫描仪最终都会模拟键盘输入)。 you need to remove that. 您需要删除它。

EDIT 编辑

as a work around please check this out... what I've done here is measure the time a key stroke takes. 作为一种变通方法,请检查一下...我在这里所做的是测量按键所花费的时间。 measure the time of a keyboard and compare is to the time it take the barcode scanner. 测量键盘时间并将其与条形码扫描仪花费的时间进行比较。 if I'm correct then the barcode scanner should be much lower then the keyboard: 如果我是正确的,那么条形码扫描仪应该比键盘低很多:

<input type="text" onkeydown="checkKeyDown(this)" onkeyup="checkKeyUp(this)" />
<script>
    var keyDownTime;

    function checkKeyDown(obj) {
        keyDownTime = new Date();
    };

    function checkKeyUp(obj) {
        var now = new Date();
        alert(now - keyDownTime);
    };
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM