0

クラスのテーブルのすべての行に2つ.js-typeのクラスtableがあり、多くの行があります。

以下を使用して、配列にすべての.js-typeオブジェクトを入力しています。

$('.js-type').each(function(){
    myArray.push($(this).text());
});

私の質問は、.tableクラスのすべての行でのみ見つかった最後の要素を同じ配列に入力する方法はありますか?

これは私が試したものです:

試行1:

$('.js-type:last-child').each(function(){
    myArray.push($(this).text());
});

試行2:

$('.js-type:last').each(function(){
    myArray.push($(this).text());
});

試行3:

$('.js-type').eq(1).each(function(){
    myArray.push($(this).text());
});

これについてのアドバイスに感謝します。

よろしくお願いします!

4

3 に答える 3

1

これを試して!

$("tr").each( function () {
    myArray.push($(this).find(".js-type").next().text());
});
于 2013-03-21T21:01:13.803 に答える
1

これにより、各行の最後の要素が取得されます。

$('.table tr>*:last-child').each(function(){
    myArray.push($(this).text());
});

これで最後の.js-type要素が得られます

$('.table tr').find('td.js-type:last-of-type').each(function(){
        myArray.push($(this).text());
    });
于 2013-03-21T21:05:05.300 に答える
0

多分このようなもの?

$("table tr").each(
    function(i, e)
    {
        myArray.push( $(e).find(".js-type").eq(1).text() );
    }
);
于 2013-03-21T21:00:18.980 に答える