jquery正在尝试绑定到稍后存在的元素

jquery正在尝试绑定到稍后存在的元素,jquery,Jquery,当下拉菜单更改时,我正在创建一个输入文本框,如下所示: var html; $('#communtiyDropdown').on('change', function () { $.ajax({ type: "GET", url: "/vendorProject/api/connection/getVendorItems?community=" + $("#communtiyDropdown").val(),

当下拉菜单更改时,我正在创建一个输入文本框,如下所示:

var html;

$('#communtiyDropdown').on('change', function () {
      $.ajax({
            type: "GET",
            url: "/vendorProject/api/connection/getVendorItems?community=" + $("#communtiyDropdown").val(),
            dataType: 'json',
            cache: false,
            success: function (results) {
                 $.each(results, function (key, value) {
                   html += "<td><input type='text' name='" + key + "-" + taskArray[i] + "' id='vendorDropdown' class='vendorDropdown' value='" + value.baseOrSchedStartList[i].split(' ')[0] + "' /></td>";
                 });
            }
            $("#tableData").html(html);
      });
});

但我的问题是,自动完成不起作用,它不会出现,而且我的控制台日志中也没有错误。。。。我做错了什么?

在您的成功回调中尝试一下,就像这样(也修复了要索引的ID):

成功:功能(结果){
var html='';
$。每个(结果、功能(键、值){
html+=“”;
});
$(“#tableData”).html(html);
$('.vendorDropdown').autocomplete({source:availableTags});
}

如果要创建具有相同id的多个元素,请使用bind DELEASE或live in代替ONY!?这不是导致问题的原因,但也需要解决。
它确实出现了
它没有出现
?在创建元素后,您是否尝试将自动完成代码放置在onchange事件中?是的,你应该修正一个事实,他们都有相同的id@user979331欢迎使用JSFIDLE链接。
var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];

    console.log(availableTags);

    $('.vendorDropdown').on('keyup', function () {
        console.log('here');
        $(this).autocomplete({
            source: availableTags
        });
    });
success: function (results) {

    var html = '';

    $.each(results, function (key, value) {
        html += "<td><input type='text' name='" + key + "-" + taskArray[i] + "' id='vendorDropdown"+[i]+"' class='vendorDropdown' value='" + value.baseOrSchedStartList[i].split(' ')[0] + "' /></td>";
    });

    $("#tableData").html(html);
    $('.vendorDropdown').autocomplete({source: availableTags});
}