javascript - 使用 jQuery 向按钮添加 Action

标签 javascript jquery html css

我有一个表,它显示不同级别的数据(父级、子级、孙子),当我单击父级时,它会显示与子级相关的新行,如果我单击子级,它会显示第三级作为孙子更多行。

我想做的是在每条记录上添加一个带有“+”符号的按钮,这样当我点击它时,我会看到第二级并将该按钮从父级切换到另一个带有“-”符号的按钮,为了模拟展开和折叠功能,我也想为子级别执行此操作。

现在,如果我单击一行,列就会展开或折叠,但如果我单击要添加的按钮,我想这样做。

这是我的代码:

    $('.drillDown tr td:last-child, .drillDown tr th:last-child').hide();

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

})


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

        var $table = $(this);
        $table.find('.parent').dblclick(function() {
            console.log( "*****Click on Parent" );
            $(this).nextUntil('.parent', ".child").toggle("fast"); 
            $(this).nextUntil('.parent', ".grandson").hide("fast");
        });

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

        });

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

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

    });

还有我对完整示例的摆弄

https://jsfiddle.net/ny6qcxtd/2/

谢谢!

最佳答案

changed with following fiddle

fiddle

关于javascript - 使用 jQuery 向按钮添加 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36417630/

相关文章:

javascript - 如何检查entry.value并更改它是否包含垃圾字符?

javascript - 无法将 getElementbyID 值插入 SQL 表

html - 如何将我的 DIV 与 CSS 对齐?

html - Bootstrap 4 表格响应,水平和垂直滚动

javascript - 只允许某些网站访问 PHP API

javascript - 对话框关闭时如何清除对话框内的表格

javascript - Node.js 使用 Socket.io 和 Http 从 Express 读取发布数据

javascript - 如何在 JQuery Flot 中制作可点击的线?

javascript - jQuery 两列高度相同

Javascript:将文本从 li 项目传递到 onclick 函数