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 に答える