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

Javascript
vml圆角矩形最简布局
DOM精简教程
[换皮肤程序]一个比较使用的脚本程序
JS中style属性
Google Suggest ;-) 基于js的动态下拉菜单
jQuery 1.0.2
PJ Blog插件-防刷新的在线播放器
使javascript也能包含文件
Dron右键菜单 v1.0
HTML里select的CSS样式的改变
仿Google和Windows Live的拖拽
"好玩的放大镜效果" 的另一种实现方法
xWin之JS版
bcastr2.0 通用的图片浏览器
addRule在firefox下的兼容写法
JS日历 推荐
用脚本调用样式的几种方法
不错的新闻标题颜色效果
用JavaScript获取网页中的js、css、Flash等文件
用js+xml自动生成表格的东西

Javascript 中的 Expandable "Detail" Table Rows


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