【问题标题】:Unable to reach child elements using right angular bracket [duplicate]无法使用右尖括号访问子元素[重复]
【发布时间】:2015-06-03 20:31:03
【问题描述】:

这就是我想要做的事情

$("table:nth-of-type(1) > tr:not(tr:nth-of-type(1))").hide();

谁知道为什么 jQuery 不支持这种选择方式?

【问题讨论】:

    标签: jquery jquery-selectors css-selectors


    【解决方案1】:

    这是因为行不是表的子级,它们是tbody 的子级:

    $("table:nth-of-type(1) > tbody > tr:not(tr:nth-of-type(1))").hide();
    

    即使您在 HTML 中没有 tbody 标记,也会为直接在表格中的 tr 标记创建一个 tbody 元素。

    【讨论】:

    • 不幸的是,表结构是不规则的。它是
      .
    • @AlexHerrmann 不过浏览器会自动插入tbody元素。
    • @AlexHerrmann:这是 HTML 代码的结构,而不是从中创建的元素的结构。如果您在浏览器中检查元素,您会看到它添加了一个tbody 元素来放入tr 元素。
    • 非常感谢!问题解决了;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 1970-01-01
    • 1970-01-01
    • 2021-03-02
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    相关资源
    最近更新 更多