How to set Default Value in tagging in select2 jquery

前端 未结 3 1140
长情又很酷
长情又很酷 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:25

    Updated version

    Say you initialized your select like this:

    $('.mySelect').select2({
      multiple: true,
      tags: "true"
    });
    

    Then use this 2 functions for triggering the change. (as seen in the official documentation)

    $('.mySelect').val(['value1', 'value2']);
    $('.mySelect').trigger('change.select2');
    

    Where "value1" and "value2" are IDs of the option elements of the select.

提交回复
热议问题