javascript - 添加第二个子 jquery 切换功能

标签 javascript jquery

我有一个表格,当您单击记录时会打开第二个级别,给用户一种感觉 进行向下钻取,现在它仅适用于一个“子级”或第二级,但我想知道的是添加第三级,因此当我单击 fiddle 上出现的任何绿色选项时,都会显示一个新级别。

这是jquery代码

$('.drillDown tr td:last-child, .drillDown tr th:last-child').hide();
$('.drillDown tr td:first-child, .drillDown tr th:first-child').click(function(){
    $('.drillDown tr td:last-child, .drillDown tr th:last-child').show();
})

$('table.drillDown').each(function() {

    var $table = $(this);
    $table.find('.parent').click(function() {
        console.log( "*****Click on Parent" );
        $(this).nextUntil('.parent').toggle("fast"); 

    });

    var $childRows = $table.find('tbody tr').not('.parent').hide();
    $table.find('button.hide').click(function() {
        $childRows.hide();

    });

    $table.find('button.show').click(function() {
        console.log("*****Click on Child");
        $childRows.filter('.child').show();
    });

    $table.find('tr.child').click(function(){
        $(this).nextUntil('.child').show()
    });

});

https://jsfiddle.net/ny6qcxtd/

感谢您的帮助!

最佳答案

我创建了第三个级别,称为孙子:D

我更新了这段代码:

        $table.find('.parent').click(function() {
            console.log( "*****Click on Parent" );
            $(this).nextUntil('.parent', ".child").toggle("fast"); 

        });

        $table.find('.child').click(function() {
            console.log( "*****Click on child" );
            $(this).nextUntil('.child', ".grandson").toggle("fast"); 

        });

您可以点击第一个 parent 和第一个 child 来查看孙子。

看:https://jsfiddle.net/ny6qcxtd/1/

关于javascript - 添加第二个子 jquery 切换功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36412667/

相关文章:

php - 将变量拉入 AJAX post 函数的数据中

php - 仅在 div 中加载 php 内容

jquery - 在页面加载时对表格进行排序

javascript - 如何更新 .focusout() 上的字段?

javascript - 使用 JavaScript 更改 HTML <p> 标记值

javascript - 主干共享集合

javascript - 可以恢复上下文菜单

javascript - Tic Tac Toe 游戏结束后禁用按钮

Javascript/jQuery 按键记录

javascript - 瓦丁与 Ajax