问题
So barcode scanners end each scan with a carriage return, which messes up forms by submitting them. Is it possible to change this so that it calls a tab instead (thus moving to the next input field)?
I did a find a solution here that does that, but it manually focused on each input using their id's. The number of inputs I have is variable so I cannot do that.
回答1:
Yes, it is possible. There are 2 ways:
- reprogram the barcode reader to send the
TAB
key instead of a carriage return after reading a barcode - use javascript to capture the submit event and inspect the form state. Either prevent submit and move focus to the next field or allow the submit event to continue based on the form state.
来源:https://stackoverflow.com/questions/15556739/barcode-scanner-and-input-fields-replace-new-line-call-to-tab-call