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

Javascript
论坛里点击别人帖子下面的回复,回复标题变成“回复 24# 的帖子”
JavaScript 撑出页面文字换行
JavaScript 高级语法介绍
Javascript 表格操作实现代码
javascript 获取鼠标的绝对位置 event
Input 特殊事件onpopertychange和oninput
javascript 一段左右两边随屏滚动的代码
JS 分号引起的一段调试问题
根据服务器时间作为起始,显示时钟的小程序
js 匿名调用实现代码
javascript 缓冲效果 实现代码
javascript htmlencode函数(ff兼容版) 主要是编辑器中反转html代码
javascript 获取radio的value的函数 [已测]
Javascript 代码也可以变得优美的实现方法
使弱类型的语言JavaScript变强势
js 单引号 传递方法
利用WebBrowser彻底解决Web打印问题(包括后台打印)
web 页面分页打印的实现
可以拖动的div 实现代码
WordPress 照片lightbox效果的运用几点

Javascript 中的 Expandable "Detail" Table Rows


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