How do I change selected value of select2 dropdown with JqGrid?

后端 未结 16 1007
遥遥无期
遥遥无期 2020-11-27 10:27

I\'m using Oleg\'s select2 demo, but I am wondering whether it would be possible to change the currently selected value in the dropdown menu.

For example, if the fou

16条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 10:53

    if you want to set a selected item when you know the text from drop down list and don't know the value, here is an example:

    Say you figured out a timezone and want to set it, but values has time_zone_id in them.

            var timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
            var $select2 = $('#time-zone');
            var selected = $select2.find("option:contains('"+timeZone+"')").val();
            $select2.val(selected).trigger('change.select2'); 
    

提交回复
热议问题