答案 0 :(得分:0)
您可以尝试这样。
handeSeach(e) {
try {
var input, filter, table, tr, td, cell, i, j;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 1; i < tr.length; i++) {
// Hide the row initially.
tr[i].style.display = "none";
td = tr[i].getElementsByTagName("td");
for (j = 0; j < td.length; j++) {
cell = tr[i].getElementsByTagName("td")[j];
if (cell) {
if (cell.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
break;
}
}
}
}
} catch (e) {
console.log(e);
}
}
然后输入。
<input
className="form-control"
type="text"
id="myInput"
onKeyUp={this.handeSeach}
placeholder="Search."
title="Type in a name"
/>