当键盘输入框和条形码扫描仪填充时检测。 [英] Detect when input box filled by keyboard and when by barcode scanner.

查看:157
本文介绍了当键盘输入框和条形码扫描仪填充时检测。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式检测何时通过键盘输入填充文本输入以及何时通过条形码扫描器自动填充文本输入?

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

推荐答案

条形码不会触发任何关键事件,因此您可以执行以下操作:

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.

这篇关于当键盘输入框和条形码扫描仪填充时检测。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆