How do I reset a jquery-chosen select option with jQuery?

前端 未结 21 757
一个人的身影
一个人的身影 2020-11-30 21:42

I have tried numerous things and nothing seems to be working.

I am using jQuery and Chosen plugin.

Methods I have tried:

var select = jQuery(         


        
21条回答
  •  佛祖请我去吃肉
    2020-11-30 22:10

    var config = {
          '.chosen-select'           : {},
          '.chosen-select-deselect'  : {allow_single_deselect:true},
          '.chosen-select-no-single' : {disable_search_threshold:10},
          '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
          '.chosen-select-width'     : {width:"95%"}
        }
        for (var selector in config) {
          $(selector).chosen(config[selector]);
        }
    

    Use above config and apply class='chosen-select-deselect' for manually deselect and set the value empty

    or if you want deselect option in all combo then apply config like below

    var config = {
      '.chosen-select'           : {allow_single_deselect:true},//Remove if you do not need X button in combo
      '.chosen-select-deselect'  : {allow_single_deselect:true},
      '.chosen-select-no-single' : {disable_search_threshold:10},
      '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
      '.chosen-select-width'     : {width:"95%"}
    }
    for (var selector in config) {
      $(selector).chosen(config[selector]);
    }
    

提交回复
热议问题