【发布时间】:2019-10-06 15:35:31
【问题描述】:
我希望表格的选定行具有某种背景颜色。 我的桌子是条纹的,它只适用于白色行。我正在使用 datatables.net。
如果选择灰色行,那么我希望灰色行的颜色相同,然后选择白色行。但是使用此代码,它会通过单击将白色行变为灰色。但是,如果我只使用第一个 if else 块,它适用于白色行。我做错了什么?
if (this.style.background == 'white') {
$(this).css('background', '#cce6ff');
} else {
$(this).css('background', 'white');
}
if (this.style.background == 'lightgrey' && this.style.background != 'white') {
$(this).css('background', '#cce6ff');
} else if (this.style.background != 'white') {
$(this).css('background', 'lightgrey');
}
这也不起作用:
if (this.style.background == 'white'){
$(this).css('background', '#b6c7db');
break;
}else{
$(this).css('background', 'white');
break;
}
if (this.style.background == 'lightgrey' && this.style.background != 'white'){
$(this).css('background', '#cce6ff');
}else if (this.style.background != 'white'){
$(this).css('background', 'lightgrey');}
【问题讨论】:
-
如果我使用 #7F7F7F 这样的#颜色,它根本不起作用......
-
为什么不在 CSS 中这样做并省去这个头疼的问题
-
希望拼写是正确的——浅灰色而不是浅灰色
-
它在 css 中不起作用。我试过了:tr.selected { background: #cce6ff !important}
-
您首先询问它是否为白色,如果是,则将其设置为颜色#cce6ff。然后在 if else 你问的不是白色然后将其设置为灰色。这就是他将其设置为灰色的原因。
标签: javascript jquery css model-view-controller datatable