折叠展开表格中的部分行(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)

 

ID Name Total
123 Bill Gates 100
456 Bill Brasky 50
789 Phil Upspace 75

你可能感兴趣的:(jquery,UI,css)