首页 技术 正文
技术 2022年11月11日
0 收藏 510 点赞 4,939 浏览 2763 个字

▓▓▓▓▓▓ 大致介绍

    在CSS技术之前,网页的布局基本都是依靠表格制作,当有了CSS之后,表格就被很多设计师所抛弃,但是表格也有他的用武之地,比如数据列表,下面以表格中常见的几个应用来加深对jQuery的认识。

▓▓▓▓▓▓ 表格变色

    基本的结构:

     <table>
<thead>
<tr><th>姓名</th><th>性别</th><th>暂住地</th></tr>
</thead>
<tbody>
<tr><td>张三</td><td>男</td><td>杭州</td></tr>
<tr><td>王五</td><td>女</td><td>江苏</td></tr>
<tr><td>李斯</td><td>男</td><td>北京</td></tr>
<tr><td>赵六</td><td>女</td><td>兰州</td></tr>
<tr><td>往往</td><td>男</td><td>酒泉</td></tr>
<tr><td>李师傅</td><td>男</td><td>东京</td></tr>
</tbody>
</table>

    1、普通的隔行变色

      首先定义两个样式

     .even{
background: #FFF38F;
}
.odd{
background: #FFFFEE;
}

    

    添加变色

     $('tr:odd').addClass('odd');
$('tr:even').addClass('even');

    2、单选框控制表格行高亮

      在每一行之前加一个单选按钮,当单击某一行后,此行被选中高亮显示并且单选框被选中

     $('tbody>tr').click(function(){
$(this)
.addClass('selected')
.siblings().removeClass('selected')
.end()
.find(':radio').attr('checked',true);
});

    3、复选框控制表格行高亮

     $('tbody>tr').click(function(){
if($(this).hasClass('selected')){
$(this).removeClass('selected')
.find(':checkbox').attr('checked',false);
}else{
$(this).addClass('selected')
.find(':checkbox').attr('checked',true);
}
});

▓▓▓▓▓▓ 表格展开关闭

    基本结构:

     <table>
<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>男</td><td>杭州</td></tr>
<tr class="child_row_01"><td></td><td>王五</td><td>女</td><td>江苏</td></tr> <tr class="parent" id="row_02"><td colspan="3">前台开发组</td></tr>
<tr class="child_row_02"><td></td><td>李斯</td><td>男</td><td>北京</td></tr>
<tr class="child_row_02"><td></td><td>赵六</td><td>女</td><td>兰州</td></tr> <tr class="parent" id="row_03"><td colspan="3">后台开发组</td></tr>
<tr class="child_row_03"><td></td><td>往往</td><td>男</td><td>酒泉</td></tr>
<tr class="child_row_03"><td></td><td>李师傅</td><td>男</td><td>东京</td></tr>
</tbody>
</table>

    添加事件,当点击一个分类的标题时,这个分类关闭或者打开

     $('tr.parent').click(function(){
$(this).toggleClass('selected')
.siblings('.child_' + this.id).toggle();
});

▓▓▓▓▓▓ 表格内容筛选

    基本结构:

     <table>
<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>男</td><td>杭州</td></tr>
<tr class="child_row_01"><td></td><td>王五</td><td>女</td><td>江苏</td></tr> <tr class="parent" id="row_02"><td colspan="3">前台开发组</td></tr>
<tr class="child_row_02"><td></td><td>李斯</td><td>男</td><td>北京</td></tr>
<tr class="child_row_02"><td></td><td>赵六</td><td>女</td><td>兰州</td></tr> <tr class="parent" id="row_03"><td colspan="3">后台开发组</td></tr>
<tr class="child_row_03"><td></td><td>往往</td><td>男</td><td>酒泉</td></tr>
<tr class="child_row_03"><td></td><td>李师傅</td><td>男</td><td>东京</td></tr>
</tbody>
</table>
<input type="text" id="filterName" />

    添加事件

     $('#filterName').keyup(function(){
$('table tbody tr').hide().filter(":contains(' "+($(this).val())+" ' )").show();
});
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,084
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,559
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,408
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,181
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,818
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,901