js读取usb扫码枪数据
作者:互联网
window.onload = function () {// 获取扫描的二维码
var code = "";
var lastTime, nextTime;
var lastCode, nextCode;
document.onkeypress = function (e) {
nextCode = e.which;
nextTime = new Date().getTime();
if (lastCode != null && lastTime != null && nextTime - lastTime <= 30) {
code += String.fromCharCode(lastCode);
} else if (lastCode != null && lastTime != null && nextTime - lastTime > 100) {
code = "";
}
lastCode = nextCode;
lastTime = nextTime;
}
this.Template_rendering = function () {
this.onkeypress = function (e) {
if (e.which == 13) {
console.log(code);
// $('#code').text(code)
readcode({code: code}); // 调用readcode方法
code = "";
}
}
}
this.Template_rendering();
};
标签:nextTime,function,扫码,code,usb,js,var,lastCode,lastTime 来源: https://www.cnblogs.com/binglicheng/p/12923134.html