2013-10-21 24 views
0

如何在每第3排中選擇每個4td?如何在每個第三個表格行中設置某個td?

我有一個jQgrid圖表和id像從每個第三行開始第一個目標客戶列。

下面是一個例子:http://jsfiddle.net/ZHRaD/13/

基本的HTML:

<tr> 
    <td></td> 
    <td></td> 
    <td></td> 
    <td></td> // << 
    <td></td> 
</tr> 
<tr> 
    <td></td> 
    <td></td> 
    <td></td> 
    <td></td> 
    <td></td> 
</tr> 
<tr> 
    <td></td> 
    <td></td> 
    <td></td> 
    <td></td> 
    <td></td> 
</tr> 
<tr> 
    <td></td> 
    <td></td> 
    <td></td> 
    <td></td> // << 
    <td></td> 
</tr> 

.... 

回答

1

您可以使用屬性DOM的<table>rows訪問<tr>元素和cells財產<tr>訪問<td>元素。相應的代碼可能看起來像

loadComplete: function() { 
    var rows = this.rows, cRows = rows.length, iRow, row, 
     iSelRows = 0; 
    for (iRow = 0; iRow < cRows; iRow++) { 
     row = rows[iRow]; // row.id is the rowid 
     if ($(row).hasClass("jqgrow")) { 
      // the row is a standard row 
      if (iSelRows%4 === 0) { 
       $(row.cells[3]).addClass("ui-state-highlight"); 
      } 
      iSelRows++; 
     } 
    } 
} 

相應的修改jsfiddle演示是here

2

使用:nth-child()

$('tr:nth-child(3n+1) td:nth-child(4)').css('color','blue'); 

更新

DEMO

$('tr:nth-child(3n-1) td:nth-child(4)').css('color','blue'); 
+1

@LivingstonStorm查看工作演示http://jsfiddle.net/cse_tushar/ZHRaD/219/ –

0

這應該做的伎倆,CSS

table tr:nth-child(1) td:nth-child(4), table tr:nth-child(4n+4) td:nth-child(4) {background:green;} 

認爲我誤讀的一點,也儘量

table tr:nth-child(3n+3) td:nth-child(4) {background:green;} 
0

$(TR:當量(2))被罰款第三行 如果判罰第三行第二列然後 $(TR:當量(2)> TD:當量(1))

因爲索引開始0

+0

歡迎!我認爲你的答案實際上應該包含一些代碼。例如,你能否將你的解決方案作爲問題中提供的jsfiddle的一個分支來實現? –

相關問題