1

すべての行と列を反復できますが、テーブルにセルが結合されている場合は機能しません。すべての通常の列(結合されたセルがない)の結合された行を通過しません。

私のスクリプト:

$('#test tr').each(function() {
   $(this).find('td').each(function(colIndex)   
    {
        if(colIndex > 1)
        {
        $(this).css('background-color', 'red');
        }
    });   
});

同様の例/テストはここで入手できます:

4

2 に答える 2

1
$('#test tr').each(function() {



    var rowcount=0;
   $(this).find('td').each(function(colIndex)   
    {
        if(colIndex > 1)
        {
        $(this).css('background-color', 'red');
        }
      rowcount ++;
    }); 
  if(rowcount==2)
  {
     $(this).find('td').each(function(colIndex)   
    {
        if(colIndex == 1)
        {
        $(this).css('background-color', 'red');
        }

    });
  }


});

jquery を次のように変更します。これで十分です。http://jsfiddle.net/dolours/pMWAw/26/

于 2013-04-11T06:22:33.793 に答える
1

1行に簡略化できます-:last-childセレクターを使用するだけです

$('#test tr td:last-child').css('background-color', 'red');

http://jsfiddle.net/pMWAw/12/

于 2013-04-11T06:28:53.160 に答える