如何在条件下使用JavaScript更改行颜色?

时间:2012-05-12 07:10:57

标签: javascript

由于某些原因,我使用此javaScript代码突出显示行。我需要为这个代码块添加条件。像这样:

 function onGridViewRowSelected(rowIdx, rowIdx2) {
   //bring value via get control and assign
var selRow = getSelectedRow(rowIdx);
//Check Current Row is null or not
if (curSelRow != null) {
   //..TRIED THIS ROW
    if (curSelRow.style.backgroundColor = '#red') {
        //do nothing..
    } else {


        curSelRow.style.backgroundColor = '#ffffff';
    }
}
//come to here if not in condition and check selected row is null or not
if (null != selRow) {
//if in condition ..
    curSelRow = selRow;
    //change current selected row background color
    curSelRow.style.backgroundColor = '#ababab';
}

}

1 个答案:

答案 0 :(得分:0)

我不清楚你的问题,但你的js代码有一个错误:

if (curSelRow.style.backgroundColor = '#red')  // WRONG, u can't do this
if (curSelRow.style.backgroundColor == '#red') // use color codes instead ( for red = #ff0000 ) or just red..