0

我有一些表格嵌套在一个单元格表中,我想用 jQuery 计算该单元格中有多少个表格,这可能吗?

<table>
<thead>
    <tr>
        <th>name</th>
        <th>age</th>
        <th>address</th>
        <th>birthday</th>
        <th>hoby</th>
        <th>country</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td colspan="6">
            <table class="groupbycountry" id="spain">
                <thead> a row of col title  </thead>
                <tbody> rows of data</tbody>
            </table>
            <table class="groupbycountry" id="italy">
                <thead>a row of col title</thead>
                <tbody>rows of data </tbody>
            </table>
            //and many more table of country according the user input 
        </td>
    </tr>
</tbody>

<tfoot>
    <tr>
        <td colspan="6">
            <table name="inputdata">
                <form name="myprofile">
                    //the input tag
                </form>
            </table>
        </td>
    </tr>
</tfoot>
</table>

是否可以计算class=groupbycountry该父表中的表?

4

2 回答 2

1

您可以使用length返回所选元素数量的 jQuery 属性,请尝试以下操作:

var len = $('table:eq(0) .groupbycountry').length

演示

于 2012-07-21T05:18:40.157 回答
1

你可以做->

var tCount = $('.groupbycountry').filter('table').length;
$('#tables').text('There are '+tCount+' tables.');

工作的jsFiddle

于 2012-07-21T05:18:52.793 回答