折叠展开表格中的部分行(JQuery)

原文地址:http://www.javascripttoolbox.com/jquery/

Expandable "Detail" Table Rows

A common UI is to have a table of data rows, which when clicked on expand to show a detailed breakdown of "child" rows below the "parent" row.

The only requirements are:

  1. Put a class of "parent" on each parent row (tr)
  2. Give each parent row (tr) an id
  3. Give each child row a class of "child-ID" where ID is the id of the parent tr that it belongs to
Example Code

<script> $(function() { $('tr.parent') .css(&quot;cursor&quot;,&quot;pointer&quot;) .attr(&quot;title&quot;,&quot;Click to expand/collapse&quot;) .click(function(){ $(this).siblings('.child-'+this.id).toggle(); }); $('tr[@class^=child-]').hide().children('td'); });</script>

$(function() {
	$('tr.parent')
		.css("cursor","pointer")
		.attr("title","Click to expand/collapse")
		.click(function(){
			$(this).siblings('.child-'+this.id).toggle();
		});
	$('tr[@class^=child-]').hide().children('td');
});
Example Table (click a row)

 

IDNameTotal
123Bill Gates100
2007-01-02A short description15
2007-02-03Another description45
2007-03-04More Stuff40
456Bill Brasky50
2007-01-02A short description10
2007-02-03Another description20
2007-03-04More Stuff20
789Phil Upspace75
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值