jQuery ui自动完成ID和关闭事件ui参数 [英] jquery ui autocomplete id and close event ui parameter
问题描述
我正在使用jQuery Ui Autocomplete 1.8.14,我想做两件事:
I am using jQuery Ui Autocomplete 1.8.14 and I would like to do two things:
为自动完成功能分配一个ID.例如,我可能在页面上有许多自动完成功能,并且需要一种识别每个自动完成功能的方法.特别是在后台,自动完成功能会生成类似
Assign an id to the autocomplete. For instance, I might have many autocompletes on page and I'd need a way to identify each. In particular, in the background autocomplete is generating something like
<ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem" style="z-index: 1; top: 444px; left: 48px; display: block; width: 118px;">
我想要给ul
标签分配ID和ID.我之所以要这样做,是出于以下原因…
What I would like is to assign and id to the ul
tag. The reason why I want to do this is for the following reason…
有一个关闭事件,其中一个参数是ui
.在选择"中,即使此ui
也会填充有用于创建自动完成的数据,但对于close事件,ui
为空.这就是为什么我想在上一个问题的ul
标记上添加一个ID.如果我可以获取ui
数据,那么尽管我认为这是一个理想的功能,但我不必费心设置id.
There is a close event and one of the parameters is ui
. In the "select" even this ui
is populated with data that is used to create the autocomplete but for the close event, ui
is empty. That's why I would like to have an id on the ul
tag in my previous question. If I can get the ui
data then I don't need to bother with setting the id although I would think that it's a desirable feature regardless.
希望我很清楚.
显然,我还不够清楚:).希望以下内容有助于阐明我的意思: 从自动完成功能中选择一个项目后,我正在使用select事件使用"ui"参数填充其他表单元素.一切正常,一切都很好.
Apparently, I wasn't clear enough :). Hopefully, the following will help clarify what I mean: After an item is selected from the autocomplete, I am using the select event to populate other form elements using the "ui" parameter. That's working all fine and great.
但是,现在我要做的就是说,在自动完成功能中,我写出了一个在自动完成功能中存在的项目.但是,我没有选择项目,而是选择了下一个表单元素.我想做的是检查在自动完成功能中输入的术语,并在自动完成功能列表中循环.如果输入的术语与列表中的一项匹配,我只是从附加的对象"中获取数据,然后相应地填充表单元素.
However, now what I want to do is this, say in the autocomplete I write out an item which exists in the autocomplete. However, I don't select the item but instead tab to the next form element. What I would like to happen is to check the term entered in the autocomplete, loop through the autocomplete list. If the term entered matches one of the items in the list, I just get the data out of the "object attached" and then populate the form elements accordingly.
推荐答案
这是 演示 我认为您可以做到.我怀疑有更好的方法可以做到这一点.我从字面上考虑了有关 TAB 的问题,并将事件绑定到了该键.
Here is a demo that I think does what you want. I suspect there is a better way of doing this though. I literally took the part of the question about TAB and bound an event to that key.
注意:我刚刚看到您对这个问题的评论,所以现在也要看一下该演示.因此,在我的演示中,JSON数据的格式不同,因此可能需要进行一些调整.
Note: I have just seen your comment on the question, so will have a look at that demo as well now. So in my demo the JSON data is in a different format, so it might need some tweaking.
哦,我刚刚找到了现有扩展名可能已经完成了您想要的操作(来自此处)典型! :-)
Oh, I've just found an existing extension that might already do what you want (from here) Typical! :-)
编辑:哦,我知道,大多数代码已经在您的小提琴中完成了.您只需使用$parentItem.data('item.autocomplete');
.
Edit Oh I see, most of the code is already done in your fiddle. All you need to just use $parentItem.data('item.autocomplete');
.
这篇关于jQuery ui自动完成ID和关闭事件ui参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!