问题
I'm working with a basic Barcode Web App. I have two textbox, so I need to scan one, and then fire an event to set the focus to the other one (the length of both textbox are not equal). If the both barcodes matches a dataBase search, display some label with the dataBase information.
Summary:
Scan one barcode, automatically set focus to the other textbox then scan the second barcode, finally display a result of the database lookup.
thanks guys!
ps. I'm working with VS 2010, asp.net and C# as codebehind.
回答1:
Using jQuery (allow just numbers to barcode):
$('#<%=yourFirstTextBox.ClientID %>').keydown(function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13) { //Enter keycode
$('#<%=yourSecondTextBox.ClientID %>').focus()
}
else if ((code >= 48 && code <= 57) || (code >= 96 && code <= 105) || (code == 8) || (code >= 37 && code <= 40) || (code == 46))
return true;
else
return false;
});
来源:https://stackoverflow.com/questions/12095444/fire-an-event-after-the-barcode-reading-and-to-set-focus-on-textbox