2012-10-06 13 views
0

我有一个扩展它下面的行中的jQuery脚本,当你点击它,我也有一台分拣机的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> 
+0

您可以根据需要在对象上添加任意数量的类。你的代码的一部分可以引用一些类,而你的代码的其他部分可以引用其他类。这不会产生冲突。你遇到的问题到底是什么?什么不工作? – jfriend00

+2

你确定你的表格标记是正确的吗?目前看起来你正在用''关闭你的行...... – ahren

+0

这里有一些代码丢失,特别是排序。 – ShaggyInjun

回答

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> 

更新:jQuery选择内使用.filter()
,而不是伪选择,感谢Ohgodwhy

+0

请不要直接在jQuery选择器中使用':'方法。您需要选择元素,然后对其进行过滤,否则我们无法利用'querySelectorAll()'。它应该是'$('#table tr')。filter(':odd')。click'。 – Ohgodwhy

+0

感谢您的提示,更新:-) – Nelson