捕获关键事件 [英] Capturing Key Event

查看:61
本文介绍了捕获关键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我想要做的就是根据用户的条目搜索一些数据。

首先,我从数据库中获取整个数据并保存在隐藏表中然后作为用户给出搜索字符串然后我从隐藏表中操作并将其显示为可见的表格。现在假设我有大量数据,并且我正在执行顺序搜索,因此每当按下按键时都会进行大量的迭代。所以它减慢了整个过程,我的意思是在整个搜索完成之后输入的字母不顺利,然后输入的键显示在文本框中。如果我输入的速度如此之快,那么平均时间浏览器被挂起了。


现在我想如果用户按下一个键然后搜索开始,如果用户在迭代结束之前再按一次键,那么迭代应该根据用户输入的内容,从开始停止并开始。因此,如果迭代没有结束,我如何捕获该事件。


请提出建议。

Actually what i am trying to do that is to search some data as per users'' entries.
Firstly i am fetching the whole data from the database and keeping in a hidden table then as user gives the search string then i manipulate from the hidden table and displaying those into visible one. Now suppose i have huge data and i am performing sequential search so a large no of iterations is going on whenever key pressed. So it slows down the whole process i mean the entered letters are not coming smoothly after the whole search finished then the entered keys displayed in the text box. and if i type so fast then in the mean time browser hanged.

Now i want if user presses a key then search starts and if user again presses key before iteration is over then iteration should stop and start from the begining as per what user typed. So how do i capture that event if the iteration does not end.

Please suggest something.

推荐答案

我建​​议首先,您要避免使用隐藏表并使用对象或数组来存储数据。这样可以避免每次查询DOM。
I would suggest, first of all, that you avoid a hidden table and use an object or array to store the data. This would avoid querying the DOM every time.


对于DOM查询来说是迟到的吗? ;)
is that late for DOM querying? ;)


我不确定你的意思。


在你原来的问题中,你可以使用一个对象来处理操纵数据。它可以有一个变量,用于表示搜索应该停止或继续,当按下另一个键时,你可以设置为false。
I''m not sure what you mean there.

In your original problem, you could use an object to deal with the manipulation of the data. It could have a variable which is used to indicate that the search should stop or continue which you can set to false when another key is pressed.


这篇关于捕获关键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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