weixin_33726313 2016-12-19 06:50 采纳率: 0%
浏览 31

Ajax追加数据以选择

I need to add the data to the database and meanwhile load into a select options menu, I successfully added the data and when loading the data gets duplicated in the options menu

function manageRow(data) {
    var rows = '';
    $.each( data, function( i, o ) {
        rows += '<option>'+o.salary_wage+'</option>';
    });
    $(".selectpicker111").append(rows);
}
  • 写回答

1条回答 默认 最新

  • ?yb? 2016-12-20 05:28
    关注

    Try this ;)

    $("selector").append(rows);
    

    This will append options to existing options and you will get duplicate options.

    There are 2 ways to get rid of duplicate options:

    Option 1:

    Remove existing options before adding options using empty and then you can add options using either append or html.

    $("selector").empty();
    

    Option 2:

    Replace existing options with new options using html

    $("selector").html(newOptions);
    

    In your case:

    $(".selectpicker111").html(rows);
    
    评论

报告相同问题?