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

Javascript
jQuery在IE中解释XML要注意的问题
JavaScript学习笔记:创建对象和构造类
JS学习笔记:Javascript类的继承
Javascript学习笔记:错误处理
JS学习笔记:防止发生命名冲突
怎么让网页全屏显示?
JS教程:addDOMLoadEvent事件
MooTools教程(告诉你为什么学Mootools)
选择mootools的5个原因
js教程:JavaScript作用域(Scope)
JS教程:日期格式转换函数
JavaScript中的Function对象
JS教程:理解JavaScript闭包
window.location.href出问题分析思路
JS教程:javascript获取页面属性
Webjx收集jQurey模式窗口的网页设计实例
现代网页设计时尚:网页中对话框窗口
概念网站实例:所有网页都在一个网页里
JS教程:鼠标悬停文字上显示图片
网页内容切换效果实现的15个jQuery插件

Javascript 中的 Expandable "Detail" Table Rows


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 126 ::
收藏到网摘: 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