【发布时间】:2014-09-29 21:54:30
【问题描述】:
我正在使用 jQuery Autocomplete 库并将该行为应用于任何具有类 typeahead 的输入。这适用于页面加载时 DOM 上的任何元素。为此,我使用append 或clone 或任何其他jQuery/Javascript 函数向DOM 添加一些HTML 来动态创建一些元素,并且它们都具有typeahead 类,但不会触发行为这个新元素。我怎么做这个工作?我也需要触发这个新元素的行为,如何?有什么建议吗?
这是触发autocomplete事件的代码:
$('#products_forms .typeahead').autocomplete({
serviceUrl: Routing.generate('get_products'),
paramName: 'filter',
showNoSuggestionNotice: true,
noSuggestionNotice: 'Nothing found',
minChars: 3,
onSelect: function(suggestion) {
alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
}
});
【问题讨论】:
标签: javascript jquery html dom