javascript - 我想在反应中过滤 html 表格数据。但我无法过滤 React.js(或仅 js)中的所有数据
问题描述
我想在 html 表中过滤所有数据。
这是我的代码
const handleSearch = e => {
setSearchTerm(e.target.value);
const input = document.getElementById("search-input");
const filter = input.value.toUpperCase();
const table = document.getElementById("patients");
const tr = table.getElementsByTagName('tr');
let td, i;
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName('td')[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > - 1) {
tr[i].style.display = '';
} else {
tr[i].style.display = 'none';
}
}
}
}
此代码导致 td[0] 结果过滤。我想过滤其他 td[i] 数据(例如,我输入文本 td[1] 或 td[2] 值,我会看到过滤 td[1] 数据或 td[2] 数据。但是,我没有知道如何过滤。请帮助我。
解决方案
推荐阅读
- scala - java.lang.ClassCastException:java.lang.String 不能转换为 scala.collection.Seq
- mysql - 无法加载caching_sha2_password
- javascript - JSON 数据验证失败
- python - 当自动增量不起作用时使列自动增量(Sqlalchemy,PostgreSQL)
- python - 如何缩短或清理此 python 代码?
- ajax - 用于 Ajax 调用的 Spring 安全会话超时处理重定向到登录不起作用
- python - python获取实例上的所有类级别属性,包括父类
- mysql - 3张表的内连接-
- sql - 在一行中获取今天和以前的可用日期数据
- html - 使用 Angular 6+ 捕获选择选项值