当前位置: 首页 > 图文教程 > 网络编程 > Javascript > Expandable "Detail" Table Rows

Javascript
[原创]js 日期加红代码 适用于各种cms
[原创]javascript 改变字体大小方法集合
jsTree树控件(基于jQuery, 超强悍)[推荐]
修改jQuery.Autocomplete插件 支持中文输入法 避免TAB、ENTER键失效、导致表单提交
jQuery live( type, fn ) 委派事件实现
javascript createElement()创建input不能设置name属性的解决方法
Jquery 表单取值赋值的一些基本操作
jquery select选中的一个小问题
网页里控制图片大小的相关代码
网页常用特效代码整理
网站上面有这种切换效果
tagName的使用,留一笔
图片按比例缩放函数
非常好的js代码
精彩图片推荐 渐隐渐现
左右图片循环滚动停顿一下后继续
popdiv
奇妙的Javascript图片放大镜
怎么用javascript进行拖拽
一个表格收缩展开的函数

Javascript 中的 Expandable "Detail" Table Rows


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 99 ::
收藏到网摘: n/a

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:
Put a class of "parent" on each parent row (tr)
Give each parent row (tr) an id
Give each child row a class of "child-ID" where ID is the id of the parent tr that it belongs to
Example Code
$(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
2007-01-02 A short description 15
2007-02-03 Another description 45
2007-03-04 More Stuff 40
456 Bill Brasky 50
2007-01-02 A short description 10
2007-02-03 Another description 20
2007-03-04 More Stuff 20
789 Phil Upspace 75
2007-01-02 A short description 33
2007-02-03 Another description 22
2007-03-04 More Stuff 20