自动完成搜索表单 cakephp
嘿,我是个新手,我正在寻找一种像谷歌一样拥有自动完成功能的搜索框的方法。
我已经搜索过,我发现的最佳前景似乎是 http://www .pengoworks.com/workshop/jquery/autocomplete.htm 我在论坛上找到的。建议它的人说他将它与 http://code.google 一起使用。 com/p/searchable-behaviour-for-cakephp/ 这是完全正确的,因为我在上次尝试弄清楚 cakephp 时成功安装了 searchable。
问题是,我以前没有使用过太多 JavaScript,而且我对我到底要做什么有点困惑。带有自动完成代码的文档没有详细介绍我能理解的任何细节。
如果我们假设我设法正确安装可搜索行为,任何好心人都可以向我解释我将如何使自动完成工作正常进行吗?
它说只使用:
$("selector").autocomplete(url [, options]);
例如:
$("#input_box").autocomplete("autocomplete_ajax.cfm");
自动完成期望存在 id 为“input_box”的输入元素。当用户开始在输入框中键入内容时,自动完成程序将使用名为 q
的 GET 参数请求 autocomplete_ajax.cfm
,
这是我没有得到的位。我应该把它放在哪里?一旦我把它放在某个地方,我是否只需要将我的输入之一命名为“input_box
”?
提前致谢。
Hey there, I'm a total newbie and I'm looking for a way to have a search box with autocomplete just like google does.
I've searched and the best prospect that I've found seems to be http://www.pengoworks.com/workshop/jquery/autocomplete.htm which I found on a forum. The guy who suggested it says he uses it with http://code.google.com/p/searchable-behaviour-for-cakephp/ which is dead on because I've managed to install searchable on my last attempt at figuring out cakephp.
The thing is, I've not used much javascript before and I'm a bit confused as to what exactly I'm meant to be doing. The documentation with the autocomplete codes doesn't go into any detail that I can understand.
If we assume that I manage to get searchable behaviour installed correctly, could any kind person explain to me how I would go about making the autocomplete work?
It says to just use:
$("selector").autocomplete(url [, options]);
eg:
$("#input_box").autocomplete("autocomplete_ajax.cfm");
Autocomplete expects an input element with the id "input_box" to exist. When a user starts typing in the input box, the autocompleter will request autocomplete_ajax.cfm
with a GET parameter named q
thats the bit I don't get. Where am I meant to put that? And once I've put it somewhere then do I just need to name one of my inputs "input_box
"?
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
共有三个步骤:
1)使用视图中的 Html 帮助器创建一个带有输入字段的完全正常的表单:
2)触发 jquery 自动完成:
3)通过控制器查询数据库以获取可能的值:
There are three steps:
1) create a totally normal form with an input field, using the Html helper in your view:
2) Have a jquery autocomplete fired:
3) Query a database through a controller to get possible values:
echo $this->Html->scriptBlock(
echo $this->Html->scriptBlock(