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

Javascript
innerHTML和innerText的用法
单击按钮复制定义好的内容到剪贴板
浏览器兼容性:停止事件冒泡和阻止浏览器的默认行为
javascript初学者:全面学习对象概念
10款图片展示Javascript代码
解决ajax跨域问题的实例
rails制作rss feed
javascript变量作用域在不同浏览器的处理
网页整理的JS技巧代码
js操作iframe的src的例子
Javascript利用循环绑定事件的例子
Javascript网页恶意代码
javascript恶意代码修改主页修复
JavaScript折叠式列表的网页制作
初学Javascript的总结
JavaScript编程实践中容易出错的地方
JavaScript容易犯错的九个陷阱
复制文章自动附加版权信息
MooTools教程(1):认识MooTools
MooTools教程(2):DOM选择器

Javascript 中的 Expandable "Detail" Table Rows


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