1

クライアントは、請求書番号 (5 桁) と「Enter」キーストロークを含むバーコードをスキャンする必要があります。

「Enter」キーを無視して、5 文字後の次の入力ボックスにフォーカスを移動するには、入力ボックスが必要です。

サンプルコードを含めていただければ幸いです。ありがとう!

4

4 に答える 4

3

テキスト ボックスの onkeypress または onkeyup を使用し、コード if(event.keyCode==13)return false; を追加します。(13 はエンター キー) 次のコントロールにフォーカスを設定します。

たとえば、2 つのテキスト ボックス (TxtBox1 と TxtBox2) があるとします。

 <input id="TxtBox1" type="submit" onkeypress="if(event.keyCode==13)return false;document.getElementById('TxtBox2').focus(); " name="Submit" value="Send" />
于 2012-05-18T18:30:13.213 に答える
2
$('input[type=text]').on('keyup', function(e) {
    if (e.which != 27 || e.which != 8) { // check for backspace and delete
        if (e.which != 13) { // ignoring enter
            if (!this.value.replace(/\s/g, '').match(/\d/g)) { // checking for digit
                alert('Insert Digit');
                $(this).val(''); // make the field empty
            } else {
                if (this.value.length > 4) {
                    $(this).next().focus(); // automatically change current input of length 5 digits
                }
            }
        }

    }
});

デモ

于 2012-05-18T18:31:18.477 に答える
0

いくつかの JQuery:

$('#test').keydown(function(e) {
if (e.which == 13) {
    if ($(this).val().length == 5) {
        e.preventDefault();
        $('#test2').focus();
    }
}
});

「test」と「test2」が 2 つのテキスト ボックスの ID であると仮定します。

于 2012-05-18T18:30:26.547 に答える
0

エンターキーを無視する代わりに、物事を進めるための合図として使用してください。次のようなもの:

$("#myTextbox").keydown(function(event){
  if(event.keyCode == 13){
  // validate input and move on to the next textbox
  }
});
于 2012-05-18T18:32:58.677 に答える