zoukankan      html  css  js  c++  java
  • js 获取扫码枪信息

    ---- js 获取扫码枪
    不需要记录 lastCode 啊,只需要在时间超出范围的时候重置 lastTime 和 code 就行了。如果
    码枪会输入回车,那就在 keyCode === 13 的时候使用 code 就行。这时候如果 code 的值多于
    1个字符就一定是码枪输入的,没有值就是手工输入的……如果需要记录手工输入的值,可以使
    用另一个变量比如 manualCode 来记录,在回车的时候如果 code 无值就从 manualCode 中截取
    后面若干字符出来,再适时把 manualCode 清空就好。

    示意(只有判断时间和拼接 code):

    let start = new Date();
    let code = "";
    $("#test").on("keydown", (e) => {
    now = new Date();
    if (now - start > 50) {
    start = now;
    code = String.fromCharCode(e.keyCode);
    } else {
    code += String.fromCharCode(e.keyCode);
    console.log(code);
    }
    });

  • 相关阅读:
    Nmap笔记
    Spring AOP(一)
    Spring IOC(三)
    Spring IOC(二)
    Spring IOC(一)
    bootstrap 使用(三)
    bootstrap 使用(二)
    bootstrap 使用(一)
    js(二)
    QQ邮件
  • 原文地址:https://www.cnblogs.com/dare/p/10913082.html
Copyright © 2011-2022 走看看