JQGRID - 是否可以在 JavaScript 中更改 HTML 标题文本的背景颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4065197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 10:18:11  来源:igfitidea点击:

JQGRID - Is it possible to change the background color of HTML header text in JavaScript?

javascripthtmlcssjqgrid

提问by David Michaeli

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 中添加它是标题文本..我很抱歉..

采纳答案by David Michaeli

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;
});

回答by Rebecca Chernoff

jQuery is not needed, you can do this with regular JavaScript.

不需要 jQuery,您可以使用常规 JavaScript 执行此操作。

document.getElementById("headerID").style.backgroundColor = "#FF0000";

回答by Oleg

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 setLabelmethod:

在您的 HTML 页面中。如果您只想对一列进行更改,您可以使用setLabel方法:

$("#myGrid").jqGrid('setLabel','Price', '', {'background':'red'});

or

或者

$("#myGrid").jqGrid('setLabel','Price', '', 'myColorClass');

In the case you cannot use background-colorbecause jqGrid use jQuery UI per default and every grid element has backgrounddefined.To overwrite this you have to use alsobackground` CSS.

在您无法使用的情况下,background-color因为 jqGrid 默认使用 jQuery UI,并且每个网格元素都已background定义。To overwrite this you have to use also背景`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/ 中使用的主题,以使结果看起来更好。

回答by Júlio Santos

Use jQuery. $("h1").css({backgroundColor:"red"})

使用 jQuery。 $("h1").css({backgroundColor:"red"})