【发布时间】:2015-04-03 13:05:30
【问题描述】:
我正在尝试创建一个从文档(而不是从输入字段)读取的按键/按键功能 - 我将其用于条形码扫描设备。
功能
$(document).keyup(function(e) {
var barcode = e.which;
// the barcode should be without the enter at the end
if (e.keyCode == 13){
// stop reading
}
});
我对 javascript 和 jQuery 还很陌生——你可能已经注意到了。
感谢您的每一个帮助!
更新
这对我有用:
$(function(){
var barcode = '';
var getCode = function (e) {
if (e.which != 13) {
barcode += String.fromCharCode(e.which);
} else {
$(document).unbind('keyup', getCode);
console.log(barcode);
}
};
$(document).on('keypress', getCode);
// Barcode ausgeben
// Produktinfos ausgeben
$('span#articleID').text('articleID');
$('span#productName').text('productName');
});
谢谢大家!!
【问题讨论】:
-
那有什么问题?
-
我不知道如何停止该功能并以变量“barcode”结束,它只是条形码 - 没有输入。它也应该是 unicode。
标签: javascript jquery keypress keyup