我想要实现的不是自动完成效果。我想要实现的是,当您在谷歌上输入时,搜索结果几乎立即出现,而无需单击搜索按钮。
我已经使用搜索按钮完成了 ajax 示例,但我希望它能够在您键入时使其工作,并在表格中显示结果。
问题是我不知道从哪里开始。
编辑:以另一种方式询问。
假设我有一个包含 1000 个名字的网格。网格已经存在于页面上。
我有一个文本框,输入时必须使用 AJAX 过滤该网格,不需要搜索按钮。
谢谢
What I want to achieve, is not the autocomplete effect. What I want to achieve is that when you type on google the search results come up almost inmediately without cliking on a search button.
I already did the ajax example with a search button, but I would like it to make it work while you type it shows the results in a table.
The problem is I have no idea where to start.
EDIT: To ask it in another way.
Lets suppose I have a grid with 1000 names. The grid is already present on the page.
I have a textbox, that when typing must filter that grid using AJAX, no search button needed.
Thanks
发布评论
评论(3)
使用
PartialView
和 jQuery.ajax。然后在您看来:
编辑
另外,您可以构建某种计时器解决方案,在 1 秒未键入内容后提交请求,这样您就不会在每次按键事件时收到请求。
Use a
PartialView
and jQuery.ajax.Then in your view:
Edit
Also, you could build in some sort of timer solution that submits the request after say 1 second of no typing, so you don't get a request on every key press event.
有一个很好的例子,您可以检查这里尝试输入's'搜索
如果这就是你想要的
那么代码和教程是这里
另一个很好的例子这里
Theres a good example you can check here try to type 's' in the search
if thats what you want
then the code and the tutorial is here
another good example here
如果您正在“过滤”页面上已存在的集合,那么您似乎想要根据搜索条件设置列表中项目的可见性。
如果是这样,那么首先,您需要为每个项目建立 HTML。您可以对每个项目使用以下内容:
然后,您必须使用一些 jquery 根据搜索条件设置每行可见/不可见:
这将导致每个项目的可见性发生变化,具体取决于搜索中的文本是否框匹配项目中的任何文本。
If you are working on "filtering" a set already located on the page, then you seem to want to set the visibility of the items in the list, based upon the search criteria.
If so, then first, you need to first establish your HTML for each item. You can use the following for each item:
Then, you must use some jquery to set each row visible/invisible based on the search criteria:
This will cause the visibility of each item to change, depending on whether or not the text in the search box matches any text in the item.