How to set selected value of jquery select2?

后端 未结 28 1388
野趣味
野趣味 2020-11-30 00:00

This belong to codes prior to select2 version 4

I have a simple code of select2 that get data from ajax



        
28条回答
  •  暖寄归人
    2020-11-30 00:40

    var $option = $("").val('1').text("Pick me");
    
    $('#select_id').append($option).trigger('change');
    

    Try this append then select. Doesn't duplicate the option upon AJAX call.

提交回复
热议问题