JQuery点击隐藏行或者列
2016-04-26 17:20
471 查看
转载自:http://www.cnblogs.com/wenzichiqingwa/archive/2012/12/03/2799350.html
NUM1:隐藏当前选中的行(点击当前选中行)
NUM2:隐藏当前选中的列(点击列标题)
CSS:
NUM1‘s jquery code:
jquery code:
NUM1:隐藏当前选中的行(点击当前选中行)
NUM2:隐藏当前选中的列(点击列标题)
<table border="1"> <thead> <tr> <th>姓名</th> <th>年龄</th> <th>性别</th> </tr> </thead> <tbody> <tr> <td>小文</td> <td>20</td> <td>男</td> </tr> <tr> <td>小李</td> <td>21</td> <td>男</td> </tr> <tr> <td>小慧</td> <td>21</td> <td>女</td> </tr> <tr> <td>琪琪</td> <td>19</td> <td>女</td> </tr> <tr> <td>小勇</td> <td>22</td> <td>男</td> </tr> <tr> <td>馨儿</td> <td>23</td> <td>女</td> </tr> <tr> <td>小鹏</td> <td>21</td> <td>男</td> </tr> <tr> <td>鸭梨山大</td> <td>30</td> <td>男</td> </tr> </tbody> </table>
CSS:
.hover{ background-color: #00f; color: #fff; }
NUM1‘s jquery code:
$('tbody tr').hover(function(){ $(this).find('td').addClass('hover'); }, function(){ $(this).find('td').removeClass('hover'); }); $('tbody tr').click(function(){ $(this).hide(); });NUM2's
jquery code:
$('th').hover(function(){ // 获取当前th的索引值 var col_index = $(this).index(); // alert(col_index); //nth-child的参数值从1开始,故索引值加1 $('tbody td:nth-child('+(col_index+1)+')').addClass('hover'); }, function(){ // 移出所有tr子元素的样式 $('tbody tr').children().removeClass('hover'); }); $('th').click(function(){ var col_index = $(this).index(); // alert(col_index); // 隐藏当前列标题 $(this).hide(); //nth-child的参数值从1开始,故索引值加1 $('tbody td:nth-child('+(col_index+1)+')').hide(); })
相关文章推荐
- jquery dataTable参数
- jQuery AJAX Call for posting data to ASP.Net page ( not Get but POST)
- jquery版本问题
- 如何去除JQuery Mobile中的默认input样式(转)
- jQuery1.72 内存泄露追踪(附解决方案)
- 浏览器窗口大小改变,onresize()事件触发两次
- 使用jQuery让事件动起来
- 基于Jquery插件实现跨域异步上传文件功能
- jQuery源码解析(架构与依赖模块)笔记二--核心模块
- jquery checkbox勾选/取消勾选的诡异问题
- jQuery javascript获得网页的高度与宽度的实现代码
- [转]jQuery选择器总结
- 使用jquery插件kkpager为页面添加分页
- jquery ui dialog 中使用select2 导致select2的input失去焦点的解决方法
- jQuery动画效果
- jQuery表单验证
- 十条jQuery代码片段助力Web开发效率提升
- jQuery中$.fn的用法示例介绍
- jQuery常用方法2
- jQuery常用方法1