首先,我不是JavaScript專家,所以答案可能很簡單,但目前我使用這個(https://www.w3schools.com/howto/howto_js_filter_table.asp)教程來過濾表格,但是你只能在1列中搜索,所以在本例中僅用於名稱或國家,但我想同時在兩列中進行搜索。使用JavaScript過濾/搜索表
這段代碼需要改變什麼?
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";
}
}
}
}