Changing selection in a select with the Chosen plugin

后端 未结 4 1817
时光说笑
时光说笑 2020-12-08 01:42

I\'m trying to change the currently selected option in a select with the Chosen plugin.

The documentation covers updating the list, and triggering an event when an o

4条回答
  •  广开言路
    2020-12-08 02:46

    From the "Updating Chosen Dynamically" section in the docs: You need to trigger the 'chosen:updated' event on the field

    $(document).ready(function() {
    
        $('select').chosen();
    
        $('button').click(function() {
            $('select').val(2);
            $('select').trigger("chosen:updated");
        });
    
    });
    

    NOTE: versions prior to 1.0 used the following:

    $('select').trigger("liszt:updated");
    

提交回复
热议问题