【问题标题】:Find all <th> within a table of certain classname在某个类名的表中查找所有 <the>
【发布时间】:2020-12-02 15:41:09
【问题描述】:

我知道这很简单,但很难让它发挥作用。

我有一个包含两个表的页面,但我只想找到一个表的&lt;th&gt;,具有特定的类名flexi-fruit

例如:

<table class="flexi-fruit">
    <colgroup>
    <col>
    <col span="2">
    </colgroup>
    <tbody>
        <tr class="header-row">
            <th>
            </th>
            <th>&nbsp;Standard&nbsp;</th>
            <th>&nbsp;Exotic&nbsp;</th>
        </tr>
        <tr>
            <td>
            Blah
            </td>
            <td>
            Blah
            </td>
            <td>
            Blah
            </td>

        </tr>

    </tbody>
</table>

所以我想在类名为flexi-fruit 的表中找到所有&lt;th&gt;s。 (然后做点什么)。

document.querySelectorAll('th.flexi-fruit') 这样的东西,显然行不通。

谢谢。

【问题讨论】:

    标签: css css-selectors document getelementsbyname


    【解决方案1】:

    您只是选择了错误的选择器。 document.querySelectorAll('table.flexi-fruit th')。 这应该有效。您的选择器将匹配所有具有类 flexi-fruit 的 th。

    【讨论】:

      【解决方案2】:

      您的 css 选择器顺序错误。参考css selector

      document.querySelectorAll('table.flexi-fruit th')
      

      【讨论】:

        猜你喜欢
        • 2014-01-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-17
        • 2015-10-01
        • 1970-01-01
        相关资源
        最近更新 更多