html5中文学习网

您的位置: 首页 > 网站及特效实例 > javascript特效 » 正文

Expandable "Detail" Table Rows_jquery_

[ ] 已经帮助:人解决问题

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)

IDNameTotal
123Bill Gates100
 2007-01-02A short description15
 2007-02-03Another description45
 2007-03-04More Stuff40
456Bill Brasky50
 2007-01-02A short description10
 2007-02-03Another description20
 2007-03-04More Stuff20
789Phil Upspace75
 2007-01-02A short description33
 2007-02-03Another description22
 2007-03-04More Stuff20
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助