js實(shí)現(xiàn)表格數(shù)據(jù)搜索
本文實(shí)例為大家分享了js實(shí)現(xiàn)表格數(shù)據(jù)搜索的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>表格數(shù)據(jù)搜索</title> <link href="../css/表格數(shù)據(jù)搜索.css" rel="stylesheet"> </head> <body> <input type="text" placeholder="搜索..." id="myInput" onkeyup="myFunction()"> <table id="myTable"> <tr> <th>名稱(chēng)</th> <th>城市</th> </tr> <tr> <td>Alfreds Futterkiste</td> <td>Germany</td> </tr> <tr> <td>Berglunds snabbkop</td> <td>Sweden</td> </tr> <tr> <td>Island Trading</td> <td>UK</td> </tr> <tr> <td>Koniglich Essen</td> <td>Germany</td> </tr> </table> <script src="../js/表格數(shù)據(jù)搜索.js"> </script> </body> </html>
CSS:
#myInput{ background: url('https://static.runoob.com/images/mix/searchicon.png')no-repeat; background-position: 10px 12px; width:100%; padding: 12px 20px 12px 40px; border:1px solid #ddd; font-size: 16px; margin-bottom: 12px; border-radius: 6px; } #myTable { width: 100%; border: 1px solid #ddd; font-size: 18px; border-collapse:collapse; } #myTable th,td{ text-align: left; padding:15px 12px; } #myTable tr{ /* 表格添加邊框 */ border-bottom:1px solid #ddd; } #myTable tr:hover{ background-color: #f1f1f1; } #myTable th{ background-color: #f1f1f1; }
JS:
function myFunction() { var myInput=document.getElementById("myInput"); var filter=myInput.value.toUpperCase(); var table=document.getElementById("myTable"); var tr=table.getElementsByTagName("tr"); //循環(huán)列表每一項(xiàng),查找匹配項(xiàng) for(var i=0;i<tr.length;i++) { var 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"; } } } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
js實(shí)現(xiàn)select跳轉(zhuǎn)功能代碼
實(shí)現(xiàn)select跳轉(zhuǎn)的方法有很多,本例為大家介紹的是js實(shí)現(xiàn)的,通過(guò)location.href獲取跳轉(zhuǎn)地址,需要的朋友可以看看2014-10-10BootStrap實(shí)現(xiàn)郵件列表的分頁(yè)和模態(tài)框添加郵件的功能
這篇文章主要介紹了bootstrap分頁(yè),模態(tài)框,實(shí)現(xiàn)郵件列表的分頁(yè),和模態(tài)框添加郵件的功能的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10詳解JavaScript實(shí)現(xiàn)監(jiān)聽(tīng)路由變化
前端實(shí)現(xiàn)路由變化主要有兩種方式,本文主要介紹了這兩種方法的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08分享一個(gè)原生的JavaScript拖動(dòng)方法
本文給大家分享的是基于JavaScript的setCapture方法實(shí)現(xiàn)的拖動(dòng)效果,非常的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下2016-09-09js 只能輸入數(shù)字和小數(shù)點(diǎn)的文本框改進(jìn)版
以前的版本不能輸入退格鍵等功能。2009-04-04js 顯示base64編碼的二進(jìn)制流網(wǎng)頁(yè)圖片
base64簡(jiǎn)單地說(shuō),它把一些 8-bit 數(shù)據(jù)翻譯成標(biāo)準(zhǔn) ASCII 字符,我們把圖像文件的內(nèi)容直接寫(xiě)在了HTML 文件中,這樣做的好處是,節(jié)省了一個(gè)HTTP 請(qǐng)求2014-04-04js判斷用戶(hù)是輸入的地址請(qǐng)求的路徑(實(shí)例講解)
下面小編就為大家?guī)?lái)一篇js判斷用戶(hù)是輸入的地址請(qǐng)求的路徑(實(shí)例講解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07