列出jQuery中的所有表头

时间:2015-08-01 08:09:47

标签: jquery

如何在jQuery中列出所有表头?我的HTML表格如下。

<table class="edit-table mobile-optimised break-words">
    <thead>
        <tr>
            <th scope="col">Location</th>
            <th scope="col">Date from/to</th>
            <th scope="col">Qty of<br>places</th>
            <th scope="col">Paid by £155.00 voucher<br>(net value)</th>
            <th scope="col">Paid by card<br>(net value)</th>
        </tr>
    </thead>
    <tbody>
        <tr class="no-records"><td colspan="5">No records to display.</td></tr>
    </tbody>
</table>

我想遍历每个<th>并获取每个文本的值。

3 个答案:

答案 0 :(得分:6)

您可以像{<1}}一样迭代

th

供参考 - http://plnkr.co/edit/zphkd8pVICzQ0zZRcOfn?p=preview

答案 1 :(得分:3)

$("table.edit-table thead tr th").each(function(){
    console.log($(this).text());
});

请参阅文档:https://api.jquery.com/each/

答案 2 :(得分:0)

我只想在这里添加一件事。像这样在您的tr中添加类:

Omit