Filtering table multiple columns

前端 未结 14 1720
闹比i
闹比i 2020-12-09 13:31

I used w3School code for my page and it works fine but it only filters one column, don’t know how create loops but hopping there is easier solution.

    td =         


        
14条回答
  •  情深已故
    2020-12-09 14:12

    You just need to add another loop to go over the cells, so:

    table = document.getElementById("myTable");
    //  tr = table.getElementsByTagName("tr");
    // Easier to use the rows collection:
    var tr = table.rows;
    
    for (i = 0; i < tr.length; i++) {
    
      // Easier to use the cells collection
      // td = tr[i].getElementsByTagName("td")[0];
      cells = row.cells;
    
      // Loop over all the cells
      for (var j=0, jLen=cells.length; j -1) {
            tr[i].style.display = "";
          } else {
            tr[i].style.display = "none";
          }
        }
      }
    }
    

提交回复
热议问题