2013-10-23 217 views
0

您好我有一个jqGrid的creaty细胞像这样其中:更改背景颜色CSS与jQuery

 <td role="gridcell" 
     title=" Hull City AFOdds: 1.74Stake: 27Ret: 46.98Ben: 0.98(Back)" 
     aria-describedby="list2_bet_2">...</td> 

我想给这个TD与jQuery自定义样式。我怎样才能访问它的CSS?

感谢

+0

谷歌'jquery css' – dezman

+0

你的问题真的是针对正确的TD或关于使用jQuery的'css()'函数吗? –

+0

http://api.jquery.com/css/ –

回答

0

如果你预先知道aria-describedby atttribute的价值,你可以针对td有:

jQuery("td[aria-describedby='list2_bet_2']") 

所以后来修改背景色

jQuery("td[aria-describedby='list2_bet_2']").css('background-color','#f00'); 
0

要设置表格中的所有TD元素:

$('td').css('background-color', 'red'); 

如果您只想设置特定的TD,请使用其他选择器。

0

如果你想测试每一行和单元格的内容,你可以做像下面这在每一行和每一颜色单元格的红色如果这两个测试的细胞该行是迭代0:

var rowIds = $(grid).jqGrid('getDataIDs'); 

for (i = 1; i <= rowIds.length; i++) { 
    rowData = $(grid).jqGrid('getRowData', i); 

    //check on TradeAmount and FoilTradeAmount Cells 
    //color background red if both are 0...the user should have to selecte a postive value of either cell 
    if (rowData['TradeAmount'] == 0 && rowData['FoilTradeAmount'] == 0) { 
     $(grid).jqGrid('setCell', i, 'TradeAmount', "", { 'background-color': '#F08080', 'background-image': 'none', 'font-weight': 'bold' }) 
     .jqGrid('setCell', i, 'FoilTradeAmount', "", { 'background-color': '#F08080', 'background-image': 'none', 'font-weight': 'bold' }); 
    } //if 
    else { 
     $(grid).jqGrid('setCell', i, 'TradeAmount', "", { 'background-color': '#5ccd06', 'background-image': 'none', 'font-weight': 'bold' }) 
     .jqGrid('setCell', i, 'FoilTradeAmount', "", { 'background-color': '#5ccd06', 'background-image': 'none', 'font-weight': 'bold' }); 
    } 
} //for 

如果你只是想在风格一列曾经电池,你可以做这样的事情

.className td[aria-describedby="GridName_RowName"] {background-color: #F08080;} 

,然后网格初始化您测试每行和每添加一个类的一部分,如果某些条件得到满足:

 rowattr: function (rd) {//if the row is displaying an inactive user, give it a different CSS style 
      if (rd.CellName!= 0) { return { "class": "DeckListMissingAmount" }; } //if 

     },