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

Javascript
mvc模式分离javascript开发
30个美观的有创意的和引人注目的灵感导航菜单
JS教程:匿名函数
JS教程:childNodes与parentNode
IE浏览器的DOM模型
使用yui3实现最简单拖动
YUI的简单的dom事件
JS区别IE6、IE7、IE8之间的方法
JavaScript教程:Table行定位效果
建立HTML字符串的最快速方法
10个美观实用的jQuery和MooTool日历插件
JS教程:Javascript实现缓动效果
Javascript小游戏贪吃蛇(详细注释)
JavaScript组件开发:分析和设计组件
JavaScript:判断iframe是否加载完成的完美方法
JS特效详解:图片幻灯片切换
JS给文本区域(textarea)字数限制
用js按比例重定图片尺寸
不用组件实现Ajax效果
PHP+JS实现搜索自动提示

Javascript 中的 Expandable "Detail" Table Rows


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