当用户输入文本时输入html catch事件 [英] html catch event when user is typing into a text input

查看:117
本文介绍了当用户输入文本时输入html catch事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



场景是,我有一个联系人,我有一个联系人,可以在我的web应用程序的文本输入字段中输入。列出网格。在表单顶部,用户可以键入他们正在尝试查找的联系人的姓名。一旦文本输入中有一个以上的字符,我想开始在系统中搜索包含用户输入的字符的联系人。因为他们一直在输入数据变化。



它实际上是一种简单的类型提前类型功能(或自动完成),但我想在不同的控件中触发数据。



一旦输入失去焦点,我可以从输入中获取文本,但这不符合情况。



有什么想法?

谢谢

解决方案

keyup事件来捕获用户键入的值,并执行任何搜索该值的操作:

  $( '(输入')。on('keyup',function(){
if(this.value.length> 1){
//在这里搜索this.value
}
});

另一个选项是输入事件,捕捉任何输入,从键盘,粘贴等。


Im just wondering how I go about catching the event when the user is typing into a text input field on my web application.

Scenario is, I have a contacts listing grid. At the top of the form the user can type the name of the contact they are trying to find. Once there is more than 1 character in the text input I want to start searching for contacts in the system which contain those characters entered by the user. As they keep typing the data changes.

All it is really is a simple type ahead type functionality (or autocomplete) but I want to fire off data in a different control.

I can get the text out of the input once the input has lost focus fine, but this doesnt fit the situation.

Any ideas?

Thanks

解决方案

Use the keyup event to capture the value as the user types, and do whatever it is you do to search for that value :

$('input').on('keyup', function() {
     if (this.value.length > 1) {
          // do search for this.value here
     }
});

Another option would be the input event, that catches any input, from keys, pasting etc.

这篇关于当用户输入文本时输入html catch事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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