Is it possible to change the background color of HTML header text in JavaScript?
是否可以在JavaScript中改变HTML标题文本的背景颜色?
Edited: oops - i did forget to add that is it header text in jqGrid.. i'm sorry about that..
编辑:噢,我忘记添加了,它是jqGrid中的标题文本。我很抱歉. .
4 个解决方案
#1
4
jQuery is not needed, you can do this with regular JavaScript.
不需要jQuery,您可以使用普通的JavaScript来实现这一点。
document.getElementById("headerID").style.backgroundColor = "#FF0000";
#2
3
If you want to set background color of all headers of the jqGrid you can include
如果您想设置jqGrid的所有标题的背景颜色,您可以包括
<style type="text/css">
.ui-jqgrid-sortable {background-color:red}
</style>
in your HTML page. If you want make the changes for one column only you can use setLabel method:
在你的HTML页面。如果您想对一列进行更改,只能使用setLabel方法:
$("#myGrid").jqGrid('setLabel','Price', '', {'background':'red'});
or
或
$("#myGrid").jqGrid('setLabel','Price', '', 'myColorClass');
In the case you cannot use background-color
because jqGrid use jQuery UI per default and every grid element has background
defined.To overwrite this you have to use also
background` CSS.
在这种情况下,不能使用背景色,因为jqGrid默认使用jQuery UI,并且每个网格元素都定义了背景。要覆盖这个,你必须使用alsobackground的CSS。
I recommend you customize and download the theme which you use in http://jqueryui.com/themeroller/ to have the results looking better.
我建议您定制并下载您在http://jqueryui.com/themeroller/中使用的主题,以使结果看起来更好。
#3
1
thanks for you all!! the answers helps me to find the answer.
谢谢你们所有人! !答案帮助我找到答案。
var HeaderFontColor = "yellow";
var HeaderBackgroundColor = "brown";
$(".ui-jqgrid-sortable").each(function() {
this.style.color = HeaderFontColor;
this.style.backgroundColor = HeaderBackgroundColor;
});
#4
0
Use jQuery. $("h1").css({backgroundColor:"red"})
使用jQuery。$(h1). css({写成backgroundColor:“红色”})
#1
4
jQuery is not needed, you can do this with regular JavaScript.
不需要jQuery,您可以使用普通的JavaScript来实现这一点。
document.getElementById("headerID").style.backgroundColor = "#FF0000";
#2
3
If you want to set background color of all headers of the jqGrid you can include
如果您想设置jqGrid的所有标题的背景颜色,您可以包括
<style type="text/css">
.ui-jqgrid-sortable {background-color:red}
</style>
in your HTML page. If you want make the changes for one column only you can use setLabel method:
在你的HTML页面。如果您想对一列进行更改,只能使用setLabel方法:
$("#myGrid").jqGrid('setLabel','Price', '', {'background':'red'});
or
或
$("#myGrid").jqGrid('setLabel','Price', '', 'myColorClass');
In the case you cannot use background-color
because jqGrid use jQuery UI per default and every grid element has background
defined.To overwrite this you have to use also
background` CSS.
在这种情况下,不能使用背景色,因为jqGrid默认使用jQuery UI,并且每个网格元素都定义了背景。要覆盖这个,你必须使用alsobackground的CSS。
I recommend you customize and download the theme which you use in http://jqueryui.com/themeroller/ to have the results looking better.
我建议您定制并下载您在http://jqueryui.com/themeroller/中使用的主题,以使结果看起来更好。
#3
1
thanks for you all!! the answers helps me to find the answer.
谢谢你们所有人! !答案帮助我找到答案。
var HeaderFontColor = "yellow";
var HeaderBackgroundColor = "brown";
$(".ui-jqgrid-sortable").each(function() {
this.style.color = HeaderFontColor;
this.style.backgroundColor = HeaderBackgroundColor;
});
#4
0
Use jQuery. $("h1").css({backgroundColor:"red"})
使用jQuery。$(h1). css({写成backgroundColor:“红色”})