-2

jquery の 1 つのテーブル行の色を赤に変更し、リストされている他のすべての行を白に設定できるようにする必要があります。

それぞれにクラスを設定しまし<tr class=row1><tr class=row2>。色を付ける必要がある現在の行 ID の JavaScript 変数はid.

ここからどこへ行けばいいですか?

4

3 に答える 3

0

jsBin デモ

$('table tr').eq(  ).css({color:'red'}).siblings().css({color:'white'});
//               ^^-- set here the index number of the row you desire to change color
于 2012-05-12T19:28:44.353 に答える
0
$('tr:eq(0)', 'table')
    .siblings('color', '#fff') // select all tr except first one and change color
    .andSelf() // target to the first one
    .css('color', '#f00'); ​​​// change color of first tr

:eq(index) ターゲット要素に応じて、内のインデックスを変更できます。

デモ

于 2012-05-12T19:31:13.930 に答える
0

私はcssを使用することをお勧めします、

たとえば、class="row1" で 3 行を赤に設定する場合は、

 .row1:nth-child(3){
     background-color: red;
  }
于 2012-05-12T19:33:42.343 に答える