0
私はテーブルをフィルタリングする簡単な検索機能を持っています。それはうまく動作します。 しかし、ヘッダーも隠します。検索のヘッダーを省略するにはどうすればよいですか?どんな助けでも大歓迎です。onkeyup関数が削除されたテーブルヘッダー
PHP/HTML:
//Create a table to display the output
echo '<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">';
echo '<div class="table-responsive">';
echo '<table id="myTable"><tr bgcolor="#cccccc"><td>Name</td><td>E-Mail Address</td><td>Office Phone</td><td>Mobile</td></tr>';
//Populate the table from LDAP
echo "<tr><td>".$LDAP_FirstName." " .$LDAP_LastName."</td><td><a class='one' href='mailto:" .$LDAP_InternetAddress. "'>" .$LDAP_InternetAddress."</td><td>".$LDAP_OfficePhone."</td><td>".$LDAP_CellPhone."</td><tr>";
echo("</table>");
echo("</div>");
スクリプト:
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";
}
}
}
}
の最初の要素をスキップしますfor-loopを 'for(i = 1; i
*スマッシュが面倒です。 noobvilleに戻る...ありがとう – user2720970