【问题标题】:Jquery- using <li> values as the source for jquery ui autocompleteJquery - 使用 <li> 值作为 jquery ui 自动完成的来源
【发布时间】:2011-10-28 17:13:24
【问题描述】:

尝试使用数字列表作为 jquery ui 自动完成的来源,但我在从列表中填充数据对象时遇到问题。这些方面的东西:

  var data

  $('.numberList li').each(function (index) {
         data += [$(this).text()];
    });


和来源:

    $("#numberText").autocomplete({
        source: data
    });

【问题讨论】:

    标签: javascript jquery jquery-ui-autocomplete javascript-objects


    【解决方案1】:

    您需要使用 push method 而不是 += 将项目添加到数组中;像这样:

    var data = [];
    $('.numberList li').each(function (index) {
         data.push($(this).text());
    });
    
    $("#numberText").autocomplete({
        source: data
    });
    

    我希望这会有所帮助!

    【讨论】:

    • 啊'ol Push 方法。谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-05
    • 1970-01-01
    • 2016-12-29
    • 2012-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多