var d = new Date();
var keyUpTime = d.getTime();
that.oneKeyTime = parseInt(keyUpTime) - parseInt(that.keyDownTime);
var isHand = that.checkHandInput();
if(isHand && that.in_range(e.which)){
layer.msg('禁止手动输入');
$(that.listenerObj).val("");
}
})
},
on_key_press : function(){
var that = this;
this.listenerObj.keypress(function(e){
if(e.which == 13 && that.check_barcode()){
that.createListEl();
}
});
},
checkHandInput : function(){
if((this.oneKeyTime > this.spanTime) || this.twoKeyTime > this.spanTime){
return true;
}else{
return false;
}
},
}
将代码整理了一下,放到了Github。
我的js代码中的提示用到了layer.js,所以如果使用按照index.html中的示例,引入相关的js:
<input id="barCode" value="" type="text" placeholder="stay focus" style="" name="">
$("#barCode").startListen({
barcodeLen : 10,
letter : true,
number : true,
show : function(code){
layer.msg(code);
}
});这里可配置的参数:包括条码的长度,是否包含英文字母,是否包含数字。以及一个show回调方法,这个方法会在扫码成功,条码合法的情况下被调用,返回条码的值,以便做自定义的操作,如上传服务器等。
代码中对页面的输入框做了stay focus,所以页面有其他的输入需求无法实现,可以除去keepFocusInput的调用。
以上所述是小编给大家介绍的使用jQuery监听扫码枪输入并禁止手动输入的实现方法(推荐),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对软件开发网网站的支持!










