日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

使用JavaScript获取扫码枪扫描得到的条形码的方法

發(fā)布時間:2024/3/26 javascript 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用JavaScript获取扫码枪扫描得到的条形码的方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
var keycode = "";var lastTime=null,nextTime;var lastCode=null,nextCode;document.οnkeydοwn=function(e){if(window.event){// IEnextCode = e.keyCode} else if(e.which){// Netscape/Firefox/OperanextCode = e.which}//+鍵,增加新數(shù)據(jù)行if(nextCode==107 || nextCode==187){addNewGoodLine();} //-鍵,刪除最后一條數(shù)據(jù)行else if(nextCode==109 || nextCode==189){$(".new_products:last").remove();}//字母上方 數(shù)字鍵0-9 對應(yīng)鍵碼值 48-57//數(shù)字鍵盤 數(shù)字鍵0-9 對應(yīng)鍵碼值 96-105else if((nextCode>=48&&nextCode<=57) || (nextCode>=96&&nextCode<=105)){//數(shù)字鍵盤的鍵碼值對應(yīng)的字符有問題,所以手動調(diào)整鍵碼值var codes = {'48':48,'49':49,'50':50,'51':51,'52':52,'53':53,'54':54,'55':55,'56':56,'57':57,'96':48,'97':49,'98':50,'99':51,'100':52,'101':53,'102':54,'103':55,'104':56,'105':57};nextCode = codes[nextCode];nextTime = new Date().getTime();if(lastCode == null && lastTime == null) {keycode = String.fromCharCode(nextCode);} else if(lastCode != null && lastTime != null && nextTime - lastTime <= 30) {keycode += String.fromCharCode(nextCode);} else{keycode = "";lastCode = null;lastTime = null;}lastCode = nextCode;lastTime = nextTime;}//13 為按鍵Enterelse if(nextCode==13 && keycode!= ""){var code = $(".new_products:last .code").val();if(code != ""){//最后一行已錄入數(shù)據(jù),重新生成新行addNewGoodLine();}$(".new_products:last .code").val(keycode).blur();keycode = "";lastCode = null;lastTime = null;}}function addNewGoodLine(){//生成新數(shù)據(jù)行var html = '<tr class="new_products">';html += ' <td></td>';html += ' <td>';html += ' <input type="text" class="code" οnblur="getProductDetail()" />';html += ' </td>';html += '</tr>';}function getProductDetail(){//獲取商品的詳細信息,然后賦值}


思路: 1.注冊onkeydown事件,捕獲數(shù)字鍵的按下事件

2.計算按下數(shù)字鍵的時間間隔,若間隔小于30毫秒,則為掃碼槍輸入

3.捕獲Enter案件的按下事件,判斷捕獲的掃碼槍輸入數(shù)值是否為空,不為空,對相應(yīng)的文本框賦值,同時觸發(fā)按找條形碼查找商品的方法


我把這篇文章的分類設(shè)定為轉(zhuǎn)載的,因為是參考網(wǎng)友的代碼,修改后得到的這段代碼

但因為網(wǎng)址被清緩存時清掉了,所以也不知道原文在哪個網(wǎng)址了

如果有覺得需要我表明來源(前提是提出要求的人是我的這段代碼的參考文章的作者),請留下聯(lián)系方式

總結(jié)

以上是生活随笔為你收集整理的使用JavaScript获取扫码枪扫描得到的条形码的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。