【发布时间】:2018-05-04 21:11:10
【问题描述】:
是否有一种按列搜索 .cshtml 表中数据的正确方法。每列必须有一个文本框。 我用javascript试过了,下面是我的代码。但它不起作用。谁能指导我正确地做到这一点?
function searchSup()
{
$('#example thead th').each
( function ()
{
var title = $(this).text();
$(this).html('<input type="text" id="SupInput" placeholder="Search ' + title + '" class="form-control"/>');
}
);
var input, filter, table, tr, td, i;
input = document.getElementById("SupInput");
filter = input.value.toUpperCase();
table = document.getElementById("SupTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++)
{
var supname = tr[i].cells[0].textContent.toUpperCase();
var contact = tr[i].cells[1].textContent.toUpperCase();
var address = tr[i].cells[2].textContent.toUpperCase();
var telephone = tr[i].cells[3].textContent.toUpperCase();
if (td)
{
if (supname.indexOf(filter) > -1 || contact.indexOf(filter) > -1 || address.indexOf(filter) > -1 || telephone.indexOf(filter) > -1)
{
tr[i].style.display = "";
}
else
{
tr[i].style.display = "none";
}
}
}
}
我在 tr = table.getElementsByTagName("tr"); 说 getElementsByTagName value is null 这一行中遇到错误
谁能帮帮我?
【问题讨论】:
-
请根据minimal reproducible example提供示例html。另请注意,您不能在页面中重复 id ......根据定义它们是唯一的
标签: javascript jquery asp.net asp.net-mvc null