如何使用数据库中的标志动态更改Flexigrid行颜色?

时间:2013-04-13 21:16:33

标签: jquery colors row flexigrid

我从json中的数据库中读取数据并将它们放在flexigrid表中。数据库表中的一个单元格名称为“color”,并且为0或1.

如果“color = 0”,如何更改蓝色的行颜色,如果“color = 1”,如何更改为红色?

我在flexigrid.js中找到了这段代码,但是无法使用它:

// If the content has a <BGCOLOR=nnnnnn> option, decode it.
var offs = td.innerHTML.indexOf( '<BGCOLOR=' );
if( offs > 0 ) {
    $(td).css('background', text.substr(offs+7,7) );
}

2 个答案:

答案 0 :(得分:0)

HTML5中不推荐使用bgcolor属性。请改用CSS background-color

答案 1 :(得分:0)

我找到了解决方案:

在flexigrid.js中找到这段代码:

// If the content has a <BGCOLOR=nnnnnn> option, decode it.
var offs = td.innerHTML.indexOf( '<BGCOLOR=' );
if( offs > 0 ) {
    $(td).css('background', text.substr(offs+7,7) );
}

并使用此

进行更改
var offs = td.innerHTML.indexOf('[BGCOLOR=');
var numcolor = td.innerHTML.substr(offs+9,7);
if(offs >= 0) {
    $(td).css('backgroundColor', numcolor);
    td.innerHTML = td.innerHTML.replace("[BGCOLOR="+numcol+"]", "");
}

现在,JSON中的每个文本 [BGCOLOR =#123456] 将被删除,数字#123456 将被设置为表格中单元格的背景颜色。

我希望这会对某人有所帮助。

相关问题