Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery更改背景颜色CSS_Jquery_Css_Jqgrid - Fatal编程技术网

使用jQuery更改背景颜色CSS

使用jQuery更改背景颜色CSS,jquery,css,jqgrid,Jquery,Css,Jqgrid,嗨,我有一个jQGrid,它可以创建如下单元格: <td role="gridcell" title=" Hull City AFOdds: 1.74Stake: 27Ret: 46.98Ben: 0.98(Back)" aria-describedby="list2_bet_2">...</td> 。。。 我想用jQuery为这个td提供一个自定义样式。我怎样才能访问它的CSS 谢谢如果您事先知道attribute所描述

嗨,我有一个jQGrid,它可以创建如下单元格:

       <td role="gridcell" 
       title=" Hull City AFOdds: 1.74Stake: 27Ret: 46.98Ben: 0.98(Back)" 
       aria-describedby="list2_bet_2">...</td>
。。。
我想用jQuery为这个td提供一个自定义样式。我怎样才能访问它的CSS


谢谢

如果您事先知道attribute所描述的
aria的值,您可以通过以下方法瞄准
td

jQuery("td[aria-describedby='list2_bet_2']")
然后修改背景色

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

要设置表的所有TD元素,请执行以下操作:

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

如果您只想设置一个特定的TD,请使用另一个选择器。

如果您想测试每一行和该单元格内容,您可以执行如下操作,在每一行上迭代,如果该行的两个测试单元格均为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
然后在网格初始化的一部分,测试每一行,如果满足某些条件,则添加一个类:

        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

        },

您的问题真的是针对正确的TD还是关于使用jQuery的
css()
函数?
        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

        },