添加字段后 jQuery UI 自动完成多个实例
我正在使用 jQuery UI 自动完成插件,并且通过 jQuery 中的 append() 动态向表单添加新字段。问题是我想创建新添加的字段和自动完成字段,因此即使具有相同的源 URL,也会有超过 1 个自动完成字段。有什么帮助吗?
谢谢。
I am using jQuery UI autocomplete plugin and I am adding new fields to the form dynamically by append() in jQuery. The problem is that i would like to make the newly added field and autocomplete field, so there would be more than 1 autocomplete field, even with same source URL. Any help ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
像这样?
此处演示。
Like this?
Demo here.
在
append()
函数之后,您将对新字段调用autocomplete()
,并为其提供与原始字段相同的源。After the
append()
function, you would callautocomplete()
on the new field, and give it the same source as the original field.我知道这是一个较旧的问题,但我遇到了同样的问题并找到了解决方案。我发现的问题是使用 JQuery 的克隆函数创建新输入。自动完成功能似乎无法显示或工作。这种情况下的问题是克隆复制了所有内容,包括指向所复制输入的自动完成信息的原始自动完成信息。
为了解决这个问题,我手动创建了克隆,然后应用了自动完成功能,它开始工作。实际上它一直在工作,但它指向原始自动完成的显示。
要手动创建输入的副本,我执行了以下操作:
I know this is an older question, but I ran across the same issue and I found a solution. The issue I found was with using JQuery's clone function to create the new input. The autocomplete will not seem to display or work. The issue in this case is that the clone copies everything including the original autocomplete information that points to the autocomplete of the input that was copied.
To resolve this I manually created the clone, then applied the autocomplete and it started working. In actuality it was always working but it was pointing to the display of the original autocomplete.
To manually create the copy of the input I did the following: