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

Javascript
文档对象模型(DOM)的技巧和诀窍
Javascript在IE与firefox中表现的异同
文档对象模型(DOM)的基本方法
javaScript DOM方法与属性摘要
Javascript的一些属性讲解
JavaScript代码规范
IE和Firefox的兼容性问题
innerHTML,outerHTML,innerText,outerText
FireFox支持innerText
JavaScript Dom编程:介绍学习书籍
JavaScript教程:关于时间格式转换
JavaScript教程:判断日期正确与否的函数
解决JS脚本兼容的几个小技巧
使用createElement动态创建HTML对象
Javascript事件处理代码的三种写法
Javascript教程:展示风格的价值
Javascript在IE和FF里的兼容问题
JavaScript扩展:正则像函数一样调用
初学Ajax须注意的几个问题
学习JavaScript的事件

Javascript 中的 Expandable "Detail" Table Rows


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