基于jquery實現(xiàn)表格內(nèi)容篩選功能實例解析
更新時間:2016年05月09日 17:12:59 作者:JsonZhang_ZY
對于表格來說,當(dāng)數(shù)據(jù)比較多的時候,我們無法一頁一頁的查找,這樣我們就可以進(jìn)行篩選操作,這篇文章主要為大家詳細(xì)介紹了基于jquery實現(xiàn)表格內(nèi)容篩選功能的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
當(dāng)表格內(nèi)的數(shù)據(jù)較多時,我們無法一頁一頁的查找,這時可以通過一個搜索框來實現(xiàn)搜索。
對于這個搜素框,我們?yōu)榱烁玫捏w驗可以利用keyup事件實現(xiàn)在用戶輸入的時候就開始篩選,而不是填完以后點擊搜索按鈕再執(zhí)行。
效果圖:
實現(xiàn)代碼:
<html> <head> <meta charset="utf-8" /> <script src="jquery-1.3.2.min.js"></script> <link href="css/style.css" rel="stylesheet" type="text/css" /> <script> $(function () { $("tr.parent").click(function () { $(this) .siblings('.child_'+this.id).toggle(); }); $("tr.parent").addClass("selected"); $("#searchbox").keyup(function () { $("table tbody tr").hide() .filter(":contains('"+($(this).val())+"')").show();//filter和contains共同來實現(xiàn)了這個功能。 }).keyup(); }); </script> <title></title> </head> <body> <label>篩選</label> <input type="text" id="searchbox"/> <table> <thead> <tr><td>姓名</td><td>性別</td><td>暫住地</td></tr> </thead> <tbody> <tr class="parent" id="row_01"><td>前臺設(shè)計組</td></tr> <tr class="child_row_01"><td>張山</td><td>男</td><td>湖北</td></tr> <tr class="child_row_01"><td>李山</td><td>男</td><td>湖北</td></tr> <tr class="child_row_01"><td>張山</td><td>男</td><td>湖北</td></tr> <tr class="child_row_01"><td>張山</td><td>男</td><td>湖北</td></tr> <tr class="parent" id="row_02"><td>前臺設(shè)計組</td></tr> <tr class="child_row_02"><td>張山</td><td>男</td><td>湖北</td></tr> <tr class="child_row_02"><td>張山</td><td>男</td><td>湖北</td></tr> <tr class="child_row_02"><td>張山</td><td>男</td><td>湖北</td></tr> <tr class="child_row_02"><td>張山</td><td>男</td><td>湖北</td></tr> <tr class="parent" id="row_03"><td>前臺設(shè)計組</td></tr> <tr class="child_row_03"><td>張山</td><td>男</td><td>湖北</td></tr> <tr class="child_row_03"><td>張山</td><td>男</td><td>湖北</td></tr> <tr class="child_row_03"><td>張山</td><td>男</td><td>湖北</td></tr> <tr class="child_row_03"><td>張山</td><td>男</td><td>湖北</td></tr> </tbody> </table> </body> </html>
以上就是本文的全部內(nèi)容,希望對大家學(xué)習(xí)jquery程序設(shè)計有所幫助。
相關(guān)文章
模仿jQuery each函數(shù)的鏈?zhǔn)秸{(diào)用
模仿jQuery each函數(shù)的鏈?zhǔn)秸{(diào)用實現(xiàn)代碼。2009-07-07jQuery EasyUI Tab 選項卡問題小結(jié)
這篇文章主要介紹了jQuery EasyUI Tab 選項卡問題小結(jié),在項目開發(fā)階段很多朋友都遇到過此問題,其實解決辦法很簡單的,下面小編給大家分享下問題原因及解決辦法,需要的朋友可以參考下2016-08-08jquery實現(xiàn)鼠標(biāo)滑過小圖時顯示大圖的方法
這篇文章主要介紹了jquery實現(xiàn)鼠標(biāo)滑過小圖時顯示大圖的方法,涉及圖片及鼠標(biāo)操作的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-01-01