现在搜索仅从第一列搜索。我从w3schools获取了代码。这是代码:
function myFunction() {
// Declare variables
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
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.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
答案 0 :(得分:1)
试试这个
$this->assertEquals(ex\Result::getUnprocessableTaskResult(), $result);
// Or
$this->assertEquals(ex\Result::getUnprocessableTaskResult()->getCode(), $result->getCode());
工作fiddle
答案 1 :(得分:0)
您还需要扩展循环以包含多个列:
//Get the column count
var columnCount = table.getElementsByTagName("tr")[0].childNodes.length;
for (i = 0; i < tr.length; i++) {
for (j = 0; j < columnCount; j++) {
td = tr[i].getElementsByTagName("td")[j];
if (td) {
var tempText;
if(td.childNodes[1].getAttribute('id')){
tempText = td.childNodes[1].getAttribute('id');
}
else {
tempText = td.innerHTML.toUpperCase();
}
try {
if (tempText.indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
catch(err) {}
}
}
}