js读取usb扫码枪数据功能代码实现
程序员文章站
2022-10-26 12:32:42
js读取usb扫码枪数据功能代码实现
js读取usb扫码枪数据功能代码实现
<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"> </head> <body class="hold-transition login-page"> <script> window.onload = function(e){ 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.onkeypress = function(e){ if(e.which == 13){ console.log(code); code = ""; } } } </script> </body> </html>