在动态创建的输入字段启用自动完成的jQuery [英] Enabling jQuery Autocomplete on dynamically created input fields
问题描述
我看过几乎每一篇文章我能找到关于如何做到这一点,但我还是失败草草收场。主要是因为我在的jQuery / JavaScript的一个业余的。
I've read almost every article i could find on how to accomplish this, but i'm still failing miserably. mostly because i'm an amateur at jQuery/Javascript.
我有一个网站,其中包含一个输入元素。我已经成功地得到jQuery的自动完成这个工作很好。的问题是,当我使用.append方法动态地添加额外的元件,但是这些新的元素不与自动填充运行。
I have a website that contains one input element. I've managed to get jQuery Autocomplete working nicely on this. The problem is that when i dynamically add additional elements using the .append method, these new elements do not work with autocomplete.
请参阅的jsfiddle: http://jsfiddle.net/aktive/r08m8vvy/
See jsfiddle: http://jsfiddle.net/aktive/r08m8vvy/
see jsfiddle for full code sample
三江源提前为您的帮助! :)
-Dean
Thankyou in advance for your help!! :) -Dean
推荐答案
您必须添加新元素后绑定自动完成
You must bind autocomplete after adding new elements
$(wrapper).find('input[type=text]:last').autocomplete({
source: availableAttributes
});
请参阅例如: http://jsfiddle.net/r08m8vvy/4/
这篇关于在动态创建的输入字段启用自动完成的jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!