jQuery在主表中仅选择tr/td,而不在嵌套表中选择. [英] jQuery select only tr/td in main table, not nested tables.

查看:177
本文介绍了jQuery在主表中仅选择tr/td,而不在嵌套表中选择.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个带有嵌套表的表:

I currently have a table with a nested table in it:

   <table class="datagrid" id="report">
       <thead>
         <tr>
          <th>item1</th>
          <th>item2</th>
         </tr>
       </thead>
       <tbody>
       <tr class="odd"> <-- on click from this level only 
        <td></td>  
        <td></td>
       </tr>
       <tr>
        <td colspan="2">
         <table>
          <tr class="odd"> <-- not to be fired here
           <td></td> 

etc表结构.

我当前正在使用以下jQuery,无论表级别如何,该jQuery都会在每个tr上触发.如何将其更改为仅在第一级射击?

I am currently using the following jQuery, which fires on every tr regardless of the table level. How do I change it to only fire on the first level?

 $(document).ready(function(){
            $("#report tr:not(.odd)").hide();
            $("#report tr:first-child").show();

            $("#report tr.odd").click(function(){
                $(this).next("#report tr").fadeToggle(600);
            });
        });

推荐答案

使用子选择器> 仅选择那些 report 表的tbody子元素的tr元素,例如:

Use the child selector > to only select those tr elements that are a child of the report table’s tbody, for example:

$("#report > tbody > tr.odd")

这篇关于jQuery在主表中仅选择tr/td,而不在嵌套表中选择.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆