首页 > 解决方案 > 使用输入框和选择框过滤 html 表

问题描述

是否可以修改当前基于多个输入过滤 html 表的现有代码,以便它也过滤所有选择框?

我最初尝试将 querySelectorAll('input') 更改为 document.querySelectorAll('input, select'),但这破坏了代码的其他部分。

  const query = q => document.querySelectorAll(q);
  
  const filters = Array.from(document.querySelectorAll('input')).map(e => new RegExp(e.value, 'i'));

  query('tbody tr').forEach(row => row.style.display = 
    filters.every((f, i) => f.test(row.cells[i + 1].textContent)) ? '' : 'none'); 

任何帮助将不胜感激。

谢谢 :)

标签: javascripthtml

解决方案


推荐阅读