0

我有一个 jquery 脚本,当您单击它时会展开它下面的行,我还有一个表排序器 jquery 对表进行排序

问题是两者都使用类<tr>来工作,所以存在冲突,我对 jquery 知之甚少,但展开/折叠行非常简单,所以我希望我可以对此查询进行一些小改动以避免与排序器jQuery

<script type="text/javascript">  
        $(function(){
    $("#table tr:odd").addClass("odd");
        $("#table tr:not(.odd)").hide();
        $("#table tr:first-child").show();
        $("#table tr.odd").click(function(){
        $(this).next("tr").toggle();

        });
        //$("#table").jExpand();
    });
</script> 

我可能低估了修复的容易程度,但如果它很容易,那就太好了。桌子设计只是一个标准

<table>
<thead>
    <tr>
        <th></th>
    </tr>
     <tr>
        <th></th>
    </tr>
 </thead>
 <tbody>
     <tr>
        <td></td>
     </tr>
     <tr>
        <td></td>
 </tr>
 </tbody>
</table>
4

1 回答 1

2

您可以通过以下方式避免在代码中添加类:

<script type="text/javascript">  
        $(function(){
           $("#table tr").not(':odd').hide();
           $("#table tr:first-child").show();
           $("#table tr").filter(':odd').click(function(){
              $(this).next("tr").toggle();

           });
        //$("#table").jExpand();
    });
</script>

更新:感谢Ohgodwhy
,在 jquery 选择器中 使用 of.filter()而不是伪选择器 。

于 2012-10-06T02:38:40.553 回答