這篇文章主要講解了如何使用JavaScript獲取掃碼槍掃描得到的條形碼,內(nèi)容清晰明了,對(duì)此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會(huì)有幫助。
成都創(chuàng)新互聯(lián)公司為客戶提供專業(yè)的網(wǎng)站設(shè)計(jì)制作、網(wǎng)站制作、程序、域名、空間一條龍服務(wù),提供基于WEB的系統(tǒng)開(kāi)發(fā). 服務(wù)項(xiàng)目涵蓋了網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站程序開(kāi)發(fā)、WEB系統(tǒng)開(kāi)發(fā)、微信二次開(kāi)發(fā)、成都手機(jī)網(wǎng)站制作等網(wǎng)站方面業(yè)務(wù)。下面通過(guò)實(shí)例代碼給大家介紹js掃碼槍掃描條形碼的實(shí)現(xiàn)方法,具體代碼如下所示:
var keycode = ""; var lastTime=null,nextTime; var lastCode=null,nextCode; document.οnkeydοwn=function(e){ if(window.event){ // IE nextCode = e.keyCode } else if(e.which){ // Netscape/Firefox/Opera nextCode = 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 對(duì)應(yīng)鍵碼值 48-57 //數(shù)字鍵盤 數(shù)字鍵0-9 對(duì)應(yīng)鍵碼值 96-105 else if((nextCode>=48&&nextCode<=57) || (nextCode>=96&&nextCode<=105)){ //數(shù)字鍵盤的鍵碼值對(duì)應(yīng)的字符有問(wèn)題,所以手動(dò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 為按鍵Enter else 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(){ //獲取商品的詳細(xì)信息,然后賦值 }
分享標(biāo)題:如何使用JavaScript獲取掃碼槍掃描得到的條形碼-創(chuàng)新互聯(lián)
分享鏈接:http://www.rwnh.cn/article38/ijpsp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、云服務(wù)器、網(wǎng)站制作、標(biāo)簽優(yōu)化、品牌網(wǎng)站制作、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容