javascript - 如何使用不同的列在 HTML 表格中进行搜索?
问题描述
我使用 JavaScript 函数过滤掉表格的行。但是,每当我输入任何内容时,所有表行都会消失。它似乎在寻找我在错误栏中搜索的单词。如何使函数在“doorName”列中显示?
搜索功能:
function SearchFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("doorTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
表的“th”标签:
<table class="table" id="doorTable" style="color:white">
<thead>
<tr>
<th>
<input type="checkbox" id="CheckAll" onclick="UnCheckAll()"/>
</th>
<th>
@Html.DisplayNameFor(model => model.CloseRight)
</th>
<th>
@Html.DisplayNameFor(model => model.OpenRight)
</th>
<th>
@Html.DisplayNameFor(model => model.doorName)
</th>
表的“td”标签:
<tr id="ScaleLine">
<td>
<input type="checkbox" id="boxCheck" class="doorNameBoxes" value=@Html.DisplayFor(modelItem => item.doorName)>
</td>
<td>
@Html.DisplayFor(modelItem => item.CloseRight)
</td>
<td>
@Html.DisplayFor(modelItem => item.OpenRight)
</td>
<td>
@Html.DisplayFor(modelItem => item.doorName)
</td>
我想在“doorName”列中搜索。
解决方案
推荐阅读
- django - 通过 www 访问。将显示 Nginx 欢迎页面 [+ Gunicorn + Django]
- java - 将价值从 Mojo 传递到 pom
- token - Hyperledger Fabric 2.0,Fab Token 源码在哪里?
- java - 合并多个流加入 Flink
- vue.js - 根据路由在组件中显示来自 Vuex 存储的数据
- php - 我如何将两行中的变量合二为一?
- https - 如何将 KeyCloak 的 https 设置为关闭模式?
- azure-devops - 用于创建发布定义的 Azure DevOps REST API
- python - 导入文本夹具时符合 PEP8 的编码样式 (F401 + F811)
- python - Pandas 剪切功能提供的类别比预期的要少