代码之家  ›  专栏  ›  技术社区  ›  Martin

使用嵌套表的jquery动画问题

  •  0
  • Martin  · 技术社区  · 16 年前

    我对在嵌套表上使用jquery的动画有问题。我想做一张有点像树视图的桌子 +/- 展开并获取有关单击行的详细信息。

    如何在Internet Explorer 6.0+和Firefox中修改动画的以下代码?

    我可以更改标记或JavaScript,只要它正常工作就没关系。

    如果知道这一点很有用,那么这个结构是使用ASP.NET中的嵌套中继器生成的。 我可以访问Telerik的Radajax控制套件,但我无法让它们的RadGrid与嵌套表一起工作。

    文件结构:

        <tr>
            <th>&nbsp;</th>
            <th>Code</th>
            <th>Title</th>
        </tr>
    
    
        <tr>
            <td><span class="TreeCollapseSign">-</span></td>
            <td>WAA-864R</td>
            <td>Code 1 ... some details ... - MODULE 2</td>        
        </tr>
    
        <tr>
            <td colspan="6">
                <table>     
                    <tr>
                        <th>Extra Info 1</th>
                        <th>Extra Info 2</th>
                        <th>Extra Info 3</th>
                    </tr>
    
                    <tr>
                        <td>Some info...</td>
                        <td>Some more info...</td>
                        <td>Yet more Info</td>
                    </tr>                                
                </table>
            </td>
        </tr>
    </table>
    

    Javascript:

    <script type="text/javascript">
        (function($) {
            $(document).ready(function(){
    
                $(".TreeCollapseSign").data("visible", true);
    
                $(".TreeCollapseSign").click(function(){
    
                    if ($(this).data("visible")) {
                        $(this).parent().parent().next().fadeOut().end().end().end().data("visible", false).text("+");                
                    } else {
                        $(this).parent().parent().next().fadeIn().end().end().end().data("visible", true).text("-");
                    }
    
                });
            });
        })($)
    </script>
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   Seb    16 年前

    是否可以更改输出代码,使用ul而不是表?

    如果可以的话,你可能想看看 jQuery Treeview plugin . 这就是我用在所有树上的。

    实际上,在语义上使用ul比使用treeview的表更合适,但在您的情况下,这取决于是否有机会更改代码。

    无论如何,如果你不能,我想你不能淡出TR的…我在过去也遇到过类似的问题,所以我建议先将内表淡出,然后隐藏tr。

    另外,调用end()3次也没有意义。如果您在显示/隐藏内部表之后再次执行$(this),它将更快、更可读:

    var innerTable = $(this).parent().parent().next().find("table");
    if ($(this).data("visible")) {
      innerTable.fadeOut();
      innerTable.parent().hide();
      $(this)
        .data("visible", false)
        .text("+");
    } else {
      innerTable.parent().show();
      innerTable.fadeIn();
      $(this)
        .data("visible", true)
        .text("-");
    }