'select all' and 'remove all' with chosen.js

前端 未结 7 1690
深忆病人
深忆病人 2020-12-24 12:29

For the select menu plugin chosen.js, is there an established way to add \'select all items in list\' or \'remove all items in list\' feature to a multiple select input? In

7条回答
  •  伪装坚强ぢ
    2020-12-24 13:05

    I realize this question is quite old, but I came upon a similar issue and wanted to share my result, as I like it's simplicity:

    I created two buttons (all and none) and floated them left and right inside the div containing my select dropdown. The buttons look something like this:

    
    
    

    Then I added some Jquery to handle the button actions:

    $('#iAll').on('click', function(e){
      e.preventDefault();
      $('#iSelect option').prop('selected', true).trigger('chosen:updated');
    });
    
    $('#iNone').on('click', function(e){
      e.preventDefault();
      $("#iSelect option:selected").removeAttr("selected").trigger('chosen:updated');
    });
    

    Will probably need some cleaning up with regards to layout, but it's quite functional as is and I thought I'd share.

提交回复
热议问题