Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.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
Javascript .addClass不会覆盖本机单元格背景色_Javascript_Css_Html - Fatal编程技术网

Javascript .addClass不会覆盖本机单元格背景色

Javascript .addClass不会覆盖本机单元格背景色,javascript,css,html,Javascript,Css,Html,我有一个从服务器端数据库填充的动态表。初始化表时,它会在表中循环,并根据条件设置特定列的背景色 function VCColor(){ var targetTable = document.getElementById('dataTable'); //Loop through table rows for (var rowIndex = 1; rowIndex < targetTable.rows.length; rowIndex++) { var

我有一个从服务器端数据库填充的动态表。初始化表时,它会在表中循环,并根据条件设置特定列的背景色

function VCColor(){
    var targetTable = document.getElementById('dataTable');

    //Loop through table rows
    for (var rowIndex = 1; rowIndex < targetTable.rows.length; rowIndex++) {
        var rowData = '';

    //  item number defines column to filter
        rowData = targetTable.rows.item(rowIndex).cells.item(12).textContent;

        if (rowData == 'N'||rowData =='n') {
            targetTable.rows.item(rowIndex).cells.item(13).style.backgroundColor= '#ff3333';
            targetTable.rows.item(rowIndex).cells.item(13).style.color= 'white';
        } else if (rowData == 'Y'||rowData =='y') {
            targetTable.rows.item(rowIndex).cells.item(12).style.backgroundColor= '#2eb82e';
            targetTable.rows.item(rowIndex).cells.item(12).style.color= 'white';
        }

    };  

};
这对没有任何预设样式的所有其他单元格都非常有效。但是,如果更新了具有预设样式的单元格;该类不会被添加,并且单元格在初始加载时保持红色/绿色。这让用户感到困惑,因为他们认为更改没有保存

我尝试用另一个类处理初始加载,但无法正确加载页面


提前谢谢

因为您的
VColor
函数将内联样式添加到表格单元格中,所以您需要使用
!重要信息
在CSS中覆盖样式

.editable_updated {
    background: green !important;
}

由于
VColor
函数将内联样式添加到表格单元格中,因此需要使用
!重要信息
在CSS中覆盖样式

.editable_updated {
    background: green !important;
}

您需要使用
!重要信息
在CSS中覆盖内联样式。为什么在声明
var$this=$(this),
而不是分号时在函数中使用逗号?@dchayka这是一种同时声明多个变量的方法<代码>变量a=1,b=2在一个语句中声明
a
b
。@MikeC啊,是的,我知道这种方法,尽管我从未使用过。谢谢。您需要使用
!重要信息
在CSS中覆盖内联样式。为什么在声明
var$this=$(this),
而不是分号时在函数中使用逗号?@dchayka这是一种同时声明多个变量的方法<代码>变量a=1,b=2在一个语句中声明
a
b
。@MikeC啊,是的,我知道这种方法,尽管我从未使用过。谢谢