为了账号安全,请及时绑定邮箱和手机立即绑定

在搜索表中为“主页”和“主页”提供相同的结果

在搜索表中为“主页”和“主页”提供相同的结果

长风秋雁 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 关注
  • 88 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信