How to set Default Value in tagging in select2 jquery

前端 未结 3 1114
长情又很酷
长情又很酷 2021-01-12 16:45

I am using select2 (http://ivaynberg.github.io/select2/) for my tagging input. from the example in using select2 tagging the code is look like this.

 $(\"#e1         


        
3条回答
  •  攒了一身酷
    2021-01-12 17:20

    For Select2 4.0 I had to add the data attribute to select2 and also set value and trigger change, like this:

    $('#mySelect').select2({
      data: ['one','two'],
      tags: true
    });
    $('#mySelect').val(['one','two']).trigger('change')
    

提交回复
热议问题