我有一个这样的表 struct :

<table1>
  <tbody>
    <tr>
      <td></td>
        ...
      <td>
        <table2>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
   </tbody>
  </table>

In javascript, I have a variable tbl with value of $(table1), and then I want to get all direct child elements (tr) of <tbody> of table1. My code is :

$('tr', tb1)

Apparently it returns all <tr> elements in table1 and table2. I think I can get by

$('tr', tb1).not(function(){return $(this).parent().parent()[0] != tb1;})

或者这种逻辑.

I know $('table1 > tbody > tr') can get the direct child tr. Unfortunately I can not use this.

有人对此有好主意吗?

谢谢

推荐答案

您可以使用find():

tbl.find("> tbody > tr")

Jquery相关问答推荐

Visual Studio - 将文本粘贴到 cshtml 中会删除文本

jQueryUI 模态对话框不显示关闭按钮 (x)

jQuery 或 JavaScript 中的$符号是什么意思?

如何使用 jquery 获取屏幕的高度

动态加载 css 样式表在 IE 上不起作用

在文本框中的最后一个字符之后设置焦点

寻找 jQuery 事件类型的完整列表

TypeScript 中是否有this的别名?

获取单选按钮组的值

JQuery手风琴自动高度问题

JQUERY UI Accordion 开始折叠

如何使用jQuery动态设置宽度和高度

即时替换 css 文件(并将新样式应用于页面)

如何将文本从 div 复制到剪贴板

JQuery:如果 div 可见

你如何在Javascript中缓存图像

jquery 检测某些类的 div 已添加到 DOM

如何使用 javascript 擦除所有内联样式并仅保留 css 样式表中指定的样式?

如何使用 JQuery 获取 GET 和 POST 变量?

如何在 DOM 中移动 iFrame 而不会丢失其状态?