jQuery UI 自动完成问题
我正在尝试让 jQuery UI 自动完成小部件正常工作,但遇到了一些问题。
首先,我尝试从数据库中检索一些数据并将它们存储在隐藏的
标记中,格式为:
item1 ;项目2; item3;
然后使用 jQuery 引用此标签并使用 .html()
(结果为 null)或 .text()
(结果为空)获取其内容细绳)。然后我决定在 jQuery 块内本地执行所有这些操作,并执行以下操作:
var tags = "house ; children's room ; master bedroom ... etc"
alert(tags); //returns them in the right format
var availableTags = tags.split(' ;');
alert(availableTags); //returns them in the form" item1, item2, item3
alert(availableTags[1]); //returns children's room
$(".liTagInput").autocomplete({
minLength: 2,
source: availableTags
});
但这仍然无法使自动完成功能正常工作...为什么它不起作用?我确保我也添加了 CSS,所以这不应该是问题...
理论上,我仍然想从数据库中检索数据。在这种情况下,我只想将标签回显到 html 页面,然后按照开头所述进行操作。在其他情况下,结果可能太大,我想通过 AJAX 获取它们,但那是另一个故事了......我需要先让它工作,然后我会担心更复杂的场景:)
任何帮助是非常感谢!
I'm trying to get the jQuery UI autocomplete widget to work but I'm having some issues.
First, I tried to retrieve some data from the database and store them inside a hidden <p>
tag in the form of: item1 ; item2; item3;
and then using jQuery reference this tag and get its content using .html()
(result was null) or .text()
(result was empty string). Then I decided to do all of this locally inside the jQuery block and did the following:
var tags = "house ; children's room ; master bedroom ... etc"
alert(tags); //returns them in the right format
var availableTags = tags.split(' ;');
alert(availableTags); //returns them in the form" item1, item2, item3
alert(availableTags[1]); //returns children's room
$(".liTagInput").autocomplete({
minLength: 2,
source: availableTags
});
But that still doesn't get the autocomplete to work... Why is it not working? I made sure I added the CSS as well, so that shouldn't be the problem...
Theoretically, I would still want to retrieve the data from the database. In this instance, I would want just echo the tags to the html page and then do as described at the beginning. In other cases where the result could be too big, I would want to get them via AJAX but that's another story... I need to get this to work first and then I'll worry about that more complex scenarios :)
Any help is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的演示按此处编码的方式工作: http://jsfiddle.net/aXuHq/
其他一些提示:
echo
到JavaScript数组中(不确定您使用的是什么服务器端技术,所以我无法提供示例),然后将其直接传递给自动完成功能。Your demo works as coded here: http://jsfiddle.net/aXuHq/
Some other tips:
echo
the tags into a JavaScript array (not sure what server-side technology you're using so I won't be able to provide an example), and pass that directly to autocomplete.