【发布时间】:2018-05-27 17:36:37
【问题描述】:
我目前有 JQuery 代码来搜索第一列上的表并按行排序。但是,它包含了我们希望从搜索中排除的其他注释信息,因此搜索仅限于系统名称信息。
SearchFilter.customfilter = function(searchInput, table) {
var input, filter, table, tr, td, i;
input = document.getElementById(searchInput);
filter = input.value.toUpperCase();
table = document.getElementById(table);
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
if (td.innerText.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
这是正在搜索的 HTML 表格的示例行:
<tr>
<td><a href="site.html">System Name</a>
<p class="tablenote"><small>Note: System note information. </small></p>
</td>
<td>N/A</td>
<td>N/A</td>
</tr>
有没有什么好办法可以修改jquery代码,把tablenote信息排除在搜索之外,比如排除那个tablenote类或者排除小文本?
【问题讨论】:
-
so.... 只看锚标签的内容。您不能只说“获取除特定子元素内部的所有内部文本”。要获得该结果,您必须改为遍历所有子节点,然后过滤掉您不想要的节点,并在剩余的节点中搜索。对于每个单元格。每一行。
-
如何只查看anchor标签的内容?你能推荐一些具体的代码吗?
-
没有。这只是 dom 遍历。
-
好的。您或其他人能否指出一些可以指导我融入隔离锚标记概念的材料?
标签: jquery html html-table