js实例教程-jquery表格内容筛选实现思路及代码

发布时间:2018-11-28 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了js实例教程-jquery表格内容筛选实现思路及代码脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

代码如下:

筛选:<input tyPE="text" id="sea" />
<table width="100%" id="se">
<thead>
<tr><th></th><th>姓名</th><th>性别</th><th>地址</th></tr>
</thead>
<tbody>
<tr class="parent" id="row_01"><td colspan="3">一班</td></tr>
<tr class="child_row_01"><td></td><td>大爷</td><td>男10</td><td>武汉1</td></tr>
<tr class="child_row_01"><td></td><td>大爷</td><td>男9</td><td>武汉2</td></tr>
<tr class="child_row_01"><td></td><td>大爷</td><td>男8</td><td>武汉3</td></tr>
<tr class="parent" id="row_02"><td colspan="3">二班</td></tr>
<tr class="child_row_02"><td></td><td>大爷</td><td>男7</td><td>武汉4</td></tr>
<tr class="child_row_02"><td></td><td>大爷</td><td>男6</td><td>武汉5</td></tr>
<tr class="child_row_02"><td></td><td>大爷</td><td>男5</td><td>武汉6</td></tr>
<tr class="child_row_02"><td></td><td>大爷</td><td>男4</td><td>武汉7</td></tr>
<tr class="parent" id="row_03"><td colspan="3">三班</td></tr>
<tr class="child_row_03"><td></td><td>大爷</td><td>男3</td><td>武汉8</td></tr>
<tr class="child_row_03"><td></td><td>大爷</td><td>男2</td><td>武汉9</td></tr>
<tr class="child_row_03"><td></td><td>大爷</td><td>男1</td><td>武汉10</td></tr>
</tbody>
</table>
<script type="text/javascript" >
$(function(){
$("#sea").keyup(function(){
$("#se tbody tr").hide().filter(":contains('"+$(this).val()+"')").show();
}).keyup();
});
</script>


. 代码如下:


// jquery表格内容筛选
<!DOCTYPE htML PubLIC "-//W3C//DTD XHTML 1.0 TransITional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html XMlns="https://www.w3.org/1999/xhtml">
<head>
<;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="../css/jquery-1.6.2.js"></script>
<script>
$(function(){
$('tr.parent').click(function(){
$(this).toggleClass("selected").siblings('.child_'+this.id).toggle();
});
});
</script>
<style>
.selected{background:red};
</style>
<title>Untitled Document</title>
</head>
<body>
<table>
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
</tr>
</thead>
<tbody>
<tr class="parent" id="row_01">
<td colspan="2">人力部</td>
</tr>
<tr class="child_row_01">
<td >脚本</td>
<td>20</td>
</tr>
<tr class="child_row_01">
<td >脚本</td>
<td >20</td>
</tr>
<tr class="child_row_01">
<td >脚本</td>
<td >20</td>
</tr>
<tr class="parent" id="row_02">
<td colspan="2">技部</td>
</tr>
<tr class="child_row_02">
<td >脚本</td>
<td >20</td>
</tr>
<tr class="child_row_02">
<td >脚本</td>
<td >20</td>
</tr>
<tr class="child_row_02">
<td >脚本</td>
<td >20</td>
</tr>
</tbody>
</table>
</body>
</html>

代码如下:

筛选:<input type="text" id="sea" />
<table width="100%" id="se">
<thead>
<tr><th></th><th>姓名</th><th>性别</th><th>地址</th></tr>
</thead>
<tbody>
<tr class="parent" id="row_01"><td colspan="3">一班</td></tr>
<tr class="child_row_01"><td></td><td>大爷</td><td>男10</td><td>武汉1</td></tr>
<tr class="child_row_01"><td></td><td>大爷</td><td>男9</td><td>武汉2</td></tr>
<tr class="child_row_01"><td></td><td>大爷</td><td>男8</td><td>武汉3</td></tr>
<tr class="parent" id="row_02"><td colspan="3">二班</td></tr>
<tr class="child_row_02"><td></td><td>大爷</td><td>男7</td><td>武汉4</td></tr>
<tr class="child_row_02"><td></td><td>大爷</td><td>男6</td><td>武汉5</td></tr>
<tr class="child_row_02"><td></td><td>大爷</td><td>男5</td><td>武汉6</td></tr>
<tr class="child_row_02"><td></td><td>大爷</td><td>男4</td><td>武汉7</td></tr>
<tr class="parent" id="row_03"><td colspan="3">三班</td></tr>
<tr class="child_row_03"><td></td><td>大爷</td><td>男3</td><td>武汉8</td></tr>
<tr class="child_row_03"><td></td><td>大爷</td><td>男2</td><td>武汉9</td></tr>
<tr class="child_row_03"><td></td><td>大爷</td><td>男1</td><td>武汉10</td></tr>
</tbody>
</table>
<script type="text/javascript" >
$(function(){
$("#sea").keyup(function(){
$("#se tbody tr").hide().filter(":contains('"+$(this).val()+"')").show();
}).keyup();
});
</script>


. 代码如下:


// jquery表格内容筛选
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="../css/jquery-1.6.2.js"></script>
<script>
$(function(){
$('tr.parent').click(function(){
$(this).toggleClass("selected").siblings('.child_'+this.id).toggle();
});
});
</script>
<style>
.selected{background:red};
</style>
<title>Untitled Document</title>
</head>
<body>
<table>
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
</tr>
</thead>
<tbody>
<tr class="parent" id="row_01">
<td colspan="2">人力部</td>
</tr>
<tr class="child_row_01">
<td >脚本</td>
<td>20</td>
</tr>
<tr class="child_row_01">
<td >脚本</td>
<td >20</td>
</tr>
<tr class="child_row_01">
<td >脚本</td>
<td >20</td>
</tr>
<tr class="parent" id="row_02">
<td colspan="2">技术部</td>
</tr>
<tr class="child_row_02">
<td >脚本</td>
<td >20</td>
</tr>
<tr class="child_row_02">
<td >脚本</td>
<td >20</td>
</tr>
<tr class="child_row_02">
<td >脚本</td>
<td >20</td>
</tr>
</tbody>
</table>
</body>
</html>

觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦!&nbsp;js技巧,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的js实例教程-jquery表格内容筛选实现思路及代码全部内容,希望文章能够帮你解决js实例教程-jquery表格内容筛选实现思路及代码所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。