如何给动态内容添加jQueryui自动补全?
How add jQuery ui auto complete to dynamic content?
我在网页中动态创建了一些输入,每个输入都需要一个带有 ajax 请求的自动完成选项。
每个输入都有相同的 class.
我为一个输入创建了它,但是当用户创建其他输入时,自动完成对它们不起作用。
我使用类似下面的东西:
$('.class').autocomplete(options);
如何解决这个问题?
只需将此添加到 ajax 代码中添加新元素的代码之后
$('.newElement').autocomplete(options);
You need to initialize autocomplete the each dynamically added element.
函数 .live() 现已弃用。
var options = {
source: ["ActionScript", "AppleScript"],
minLength: 2
};
var selector = 'input.searchInput';
$(document).on('keydown.autocomplete', selector, function() {
$(this).autocomplete(options);
});
我在网页中动态创建了一些输入,每个输入都需要一个带有 ajax 请求的自动完成选项。 每个输入都有相同的 class.
我为一个输入创建了它,但是当用户创建其他输入时,自动完成对它们不起作用。
我使用类似下面的东西:
$('.class').autocomplete(options);
如何解决这个问题?
只需将此添加到 ajax 代码中添加新元素的代码之后
$('.newElement').autocomplete(options);
You need to initialize autocomplete the each dynamically added element.
函数 .live() 现已弃用。
var options = {
source: ["ActionScript", "AppleScript"],
minLength: 2
};
var selector = 'input.searchInput';
$(document).on('keydown.autocomplete', selector, function() {
$(this).autocomplete(options);
});