Select2 - make it readonly (not disabled!) from js

前端 未结 5 1312
自闭症患者
自闭症患者 2021-02-12 12:05

How can I dynamically make a select2 combobox read-only?

Here\'s what I\'ve tried so far:

$(\'...\').attr({\'reado         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-12 12:55

    I'm working with Select 4.0 and this works well for me

    $('#select2-element').on('select2:select', () => {
      $('#select2-element').data('select2').destroy();
      $('#select2-element').attr('readonly', true);
    });
    

提交回复
热议问题