亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在搜索表中為“主頁”和“主頁”提供相同的結果

在搜索表中為“主頁”和“主頁”提供相同的結果

長風秋雁 2023-07-14 15:04:48
這是一個搜索表并且運行良好。但我希望這樣寫“主頁”和“主頁”。在這兩種情況下,它都會顯示主頁的結果。“關于我們”和“聯系我們”類似。代碼如下。請任何人幫助我#myInput {      padding: 12px 20px 12px 40px;  border: 5px solid #ddd;  margin-bottom: 12px;  border-radius:20px;}<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Search your product here"><table id="myTable" align="center" border="5" width>  <tr class="header">    <th>Header 1 </th>    <th>Header 2</th>  </tr>  <tr>    <td><center><br><b>Home page</b></a></center></td>    <td>   </td>  </tr>  <tr>    <td><center>        <br><b>About us</b></a></center></td>    <td>        </td>  </tr><tr>    <td><center>        <br><b>Contact us</b></a></center></td>    <td>        </td>  </tr></table>function myFunction() {  var input, filter, table, tr, td, i, txtValue;  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) {      txtValue = td.textContent || td.innerText;      if (txtValue.toUpperCase().indexOf(filter) > -1) {        tr[i].style.display = "";      } else {        tr[i].style.display = "none";      }    }         }}
查看完整描述

2 回答

?
呼喚遠方

TA貢獻1856條經驗 獲得超11個贊

使用正則表達式替換空格


filter = filter.replace(/\s/g, '')

編輯評論


filter = filter.replace(/\s/g,'')

txtValue = txtValue.replace(/\s/g, '')

if (txtValue.toUpperCase().indexOf(filter) > -1) {

  tr[i].style.display = "";    

} else {

  tr[i].style.display = "none";

}


查看完整回答
反對 回復 2023-07-14
?
交互式愛情

TA貢獻1712條經驗 獲得超3個贊

使用正則表達式模式刪除所有空格


let str = "Hello World !";

let spacesRemoved = str.replace(/ /g, "");

console.log(spacesRemoved);


查看完整回答
反對 回復 2023-07-14
  • 2 回答
  • 0 關注
  • 197 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號