简体   繁体   English

jQuery UI自动完成功能不适用于Ajax加载的表单

[英]jQuery UI autocomplete is not working with ajax loaded form

this is my code and I am using jQuery UI to implement an autocomplete field 这是我的代码,我正在使用jQuery UI来实现自动完成字段

 jQuery( function() {
    jQuery( ".product-category" ).on('keydown.autocomplete', {
        source: ''
    });
} );

but jQuery UI autocomplete is not working for dynamically generated text fields. 但jQuery UI自动完成功能不适用于动态生成的文本字段。

You can implement autocomplete on dynamically generated input elements as. 您可以像这样对动态生成的输入元素实现自动完成。

var selector = 'input.searchInput';
$(document).on('keydown.autocomplete', selector, function() {
    $(this).autocomplete(options);
});

Demo: https://jsfiddle.net/waw2vhb7/ 演示: https : //jsfiddle.net/waw2vhb7/

The solution is to reload your jQuery function after the DOM changes / form is done loading from the ajax request. 解决方案是从ajax请求加载完DOM更改/表单后,重新加载jQuery函数。 jQuery only detects DOM that's currently loaded when it runs. jQuery仅在运行时检测到当前正在加载的DOM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM