我對Java編碼完全陌生。我有一個帳戶清單,我用它來顯示正確的收集器(超過5000行)。我已經使用一些在線幫助將其轉換爲HTML網頁。在搜索框中沒有查詢時自動隱藏行
現在我想,當在搜索框中沒有查詢時,下表中不應該有任何結果,只有標題應該出現。只要我開始輸入任何客戶名稱,並且如果有任何匹配,就會顯示出來,只要我刪除查詢,列表就會消失。
以下是我目前使用的代碼。
<!DOCTYPE html>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
#myInput {
background-image: url('/css/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
width: 26%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}
#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 12px;
}
#myTable th, #myTable td {
text-align: left;
padding: 2px;
}
#myTable tr {
border-bottom: 1px solid #ddd;
}
#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<img src="res/logo.jpg" style="width:350px;height:100px;">
<h2><font face="Arial" color="#c11919">Collector Lookup Tool - Test Phase</font></h2>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for customer names" title="Type in a name">
<table id="myTable">
<tr class="header">
<th style="width:20%;">Customer Name</th>
<th style="width:10%;">Collector Name</th>
<th style="width:15%;">Collector e-mail</th>
<th style="width:10%;">Region</th>
<th style="width:20%;">Telnet</th>
</tr>
<tr><td>110 Technology LLC</td><td>Abhishek Yadav</td><td>[email protected]</td><td>Americas</td><td>2684227</td></tr>
<tr><td>14 WFIE TV</td><td>Abhishek Yadav</td><td>[email protected]</td><td>Americas</td><td>2684227</td></tr>
<tr><td>2Wire Inc</td><td>Abhishek Yadav</td><td>[email protected]</td><td>Americas</td><td>2684227</td></tr>
<tr><td>3 Phoenix LLC</td><td>Abhishek Yadav</td><td>[email protected]</td><td>Americas</td><td>2684227</td></tr>
<tr><td>3 Sixty Mfg</td><td>Abhishek Yadav</td><td>[email protected]</td><td>Americas</td><td>2684227</td></tr>
<tr><td>3D at Depth LLC</td><td>Abhishek Yadav</td><td>[email protected]</td><td>Americas</td><td>2684227</td></tr>
.
.
.
.
.
.
</table>
<script>
function myFunction() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
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";
}
}
}
}
</script>
</body>
</html>
這裏是鏈接到的樣本文件以供參考 https://drive.google.com/file/d/0B_a89TkNd6sCVGRyNzd6UlI0VDA/view?usp=sharing –