How can I reset a form with jQuery chosen plugin?

后端 未结 10 1303
甜味超标
甜味超标 2020-12-04 15:12

I have a bunch of select elements in a form with which I am using the Jquery Chosen plugin. How can I reset the form? The following does not work:



        
10条回答
  •  独厮守ぢ
    2020-12-04 15:43

    Sometimes you have to reset the select that chosen is called on.

    I do this

    jQuery.fn.chosen_reset = function(n){
      $(this).chosen('destroy');
      $(this).prop('selectedIndex', 0);
      $(this).chosen(n)
    }
    

    And call this function like this, with the options as an argument

    $('select').chosen_reset({width:'369px'});
    

提交回复
热议问题