Different display value for selecte text using select2.js

后端 未结 5 2134
闹比i
闹比i 2021-01-18 15:24

Trying to implement a custom select dropdown using select2 plugin Is it possible to have the selected value to display only the actual option \'value\' instead of the text,

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-18 16:00

    You can try this

    $('select').select2({
        width: 300
    }).change(function () {
        $('a.select2-choice span').text($(this).val()); 
        // change select2 span to the selected value
    }).trigger('change');
        // trigger change the first time so the displayed text will change to value
    

    Test it here

提交回复
热议问题