js實(shí)現(xiàn)表格篩選功能
本應(yīng)用就兩個主要實(shí)現(xiàn):
1.表格的id 和 class之間的命名關(guān)系
請看圖: 將組名和個人信息聯(lián)表格聯(lián)系起來,這樣會很好的操作表格
HTML代碼:
<tr class="parent" id="row_01"><td colspan="3">前臺設(shè)計(jì)組</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 colspan="3">前臺開發(fā)組</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>
2.就是篩選功能的使用:使用filter聯(lián)合contains將輸入框的字加入contains進(jìn)行篩選
javascript代碼:
//設(shè)置列表查詢 $("#filterName").keyup(function () { $("table tbody tr").stop().hide() //將tbody中的tr都隱藏 .filter(":contains('"+($(this).val())+"')").show(); //,將符合條件的篩選出來 });
下面是完整代碼:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>表格應(yīng)用</title> <style> *{ margin: 0; padding: 0; } .box{ border: 1px solid #000; margin:50px auto; width: 340px; padding: 10px 10px; } .box table{ margin: auto; } .box .box-top{ width: 303px; margin: 5px auto; } .box table tr td,th{ padding: 5px 30px; text-align: center; } .box table .parent{ background: lightgray; } .selected{ background: gray !important; } .selectHeight{ background: darkseagreen !important; } </style> </head> <body> <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <script> $(function () { //默認(rèn)讓王五選中 $("tr:contains('王五')").addClass("selectHeight") //點(diǎn)擊讓其展示出列表 默認(rèn)讓其都隱藏 $(".box tr.parent").click(function () { $(this) .toggleClass("selected") .siblings(".child_"+this.id).stop().toggle(); }).click();//此行代碼表示要立即執(zhí)行 //設(shè)置列表查詢 $("#filterName").keyup(function () { $("table tbody tr").stop().hide() //將tbody中的tr都隱藏 .filter(":contains('"+($(this).val())+"')").show(); //,將符合條件的篩選出來 }); }); </script> <div class="box"> <div class="box-top"> <span>篩選:</span><input type="text" id="filterName"> </div> <table> <thead> <tr> <th>姓名</th> <th>性別</th> <th>暫住地</th> </tr> </thead> <tbody> <tr class="parent" id="row_01"><td colspan="3">前臺設(shè)計(jì)組</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 colspan="3">前臺開發(fā)組</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 colspan="3">后臺設(shè)計(jì)組</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> </div> </body> </html>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
- jquery遍歷篩選數(shù)組的幾種方法和遍歷解析json對象
- 基于JavaScript實(shí)現(xiàn)前端數(shù)據(jù)多條件篩選功能
- JS實(shí)現(xiàn)table表格內(nèi)針對某列內(nèi)容進(jìn)行即時搜索篩選功能
- Angularjs實(shí)現(xiàn)帶查找篩選功能的select下拉框示例代碼
- vuejs通過filterBy、orderBy實(shí)現(xiàn)搜索篩選、降序排序數(shù)據(jù)
- Vue.js實(shí)現(xiàn)多條件篩選、搜索、排序及分頁的表格功能
- JS實(shí)現(xiàn)商品篩選功能
- Jquery遍歷篩選數(shù)組的幾種方法和遍歷解析json對象,Map()方法詳解以及數(shù)組中查詢某值是否存在
- angularjs 實(shí)現(xiàn)帶查找篩選功能的select下拉框?qū)嵗?/a>
- js實(shí)現(xiàn)篩選功能
相關(guān)文章
jQuery實(shí)現(xiàn)點(diǎn)擊后高亮背景固定顯示的菜單效果【附demo源碼下載】
這篇文章主要介紹了jQuery實(shí)現(xiàn)點(diǎn)擊后高亮背景固定顯示的菜單效果,可實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊菜單項(xiàng)后呈現(xiàn)出鼠標(biāo)滑過一樣的背景高亮顯示效果,同時該顯示效果固定不變,需要的朋友可以參考下2016-09-09多個datatable共存造成多個表格的checkbox都被選中
所以當(dāng)有多個datatable 引用到一個頁面中的時候,全選事件會匹配全部的datatable,所以造成全部多個表格的checkbox被都被選中2013-07-07Jquery公告滾動+AJAX后臺得到數(shù)據(jù)
ajax得到值,用JQUERY綁定給對應(yīng)的UL.利用JQUERY的動畫來實(shí)現(xiàn)他們的滾動公告。2011-04-04jquery easyui validatebox remote的使用詳解
下面小編就為大家?guī)硪黄猨query easyui validatebox remote的使用詳解。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11jquery實(shí)現(xiàn)的鼠標(biāo)拖動排序Li或Table
這篇文章主要介紹了使用jquery實(shí)現(xiàn)的鼠標(biāo)拖動排序Li或Table,需要的朋友可以參考下2014-05-05基于jquery編寫的橫向自適應(yīng)幻燈片切換特效的實(shí)例代碼
全屏自適應(yīng)jquery焦點(diǎn)圖切換特效,在IE6這個瀏覽器兼容性問題上得到了和諧,兼容IE6,適用瀏覽器:IE6、IE7、IE8、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗.相關(guān)代碼2013-08-08