Detect when input box filled by keyboard and when by barcode scanner.

前端 未结 11 2073
星月不相逢
星月不相逢 2020-12-01 00:44

How I can programmatically detect when text input filled by typing on keyboard and when it filled automatically by bar-code scanner?

11条回答
  •  一向
    一向 (楼主)
    2020-12-01 01:17

    Well a barcode won't fire any key events so you could do something like:

    $('#my_field').on({
        keypress: function() { typed_into = true; },
        change: function() {
            if (typed_into) {
                alert('type');
                typed_into = false; //reset type listener
            } else {
                alert('not type');
            }
        }
    });
    

    Depending on when you want to evaluate this, you may want to do this check not on change but on submit, or whatever.

提交回复
热议问题