条码枪扫码后input会自动提交 (亲测有效)可以区分手动输入与条码枪扫码
程序员文章站
2022-03-04 14:05:15
...
var lastTime = null,
nextTime = null,
codess = '';
//条码枪扫码
var myInputOrder = document.getElementById('code_new');
myInputOrder.onkeydown = function (e) {
let keycode = e.keyCode || e.which || e.charCode;
nextTime = new Date();
if (keycode === 13) {
inputisbns = myInputOrder.value;
if (lastTime && (nextTime - lastTime < 30)) {//扫码枪
if(inputisbns){
相关操作
}
} else{//手动输入
if(inputisbns){
相关操作
}
}
codess = '';
lastTime = null;
e.preventDefault();
} else {
if (!lastTime) {
codess = String.fromCharCode(keycode);
} else {
if (nextTime - lastTime < 30) {
codess += String.fromCharCode(keycode);
} else {
codess = '';
}
}
lastTime = nextTime;
}
};
https://www.jianshu.com/p/3019858e3cad
上一篇: [Scala]学习笔记三——面向对象
下一篇: 快学Scala(七)--包和引入简单示例