Checkboxes + Jquery hide/show

后端 未结 3 1476
甜味超标
甜味超标 2021-01-20 16:18

I have a series of a series of rows and checkboxes to filter them:

  • &l
3条回答
  •  时光说笑
    2021-01-20 17:08

    Modify the function to get a selector for all the checked check boxes.

    $(function(){
      var $checkboxes = $("input[id^='type-']");
      $checkboxes.change(function() {
        var selector = '';
        $checkboxes.filter(':checked').each(function(){ // checked 
            selector += '.' + this.id.replace('type-','') + ', '; 
            // builds a selector like '.A, .B, .C, ' 
        });
        selector = selector.substring(0, selector.length - 2); // remove trailing ', '
        // tr selector
        $('table tr').hide() // hide all rows
           .filter(selector).show(); // reduce set to matched and show
      }).change(); 
    });
    

    EDIT: see jsfiddle

提交回复
热议问题