简体   繁体   English

在Java脚本中更改字体颜色

[英]Changing font color in java script

$("table[class='ms-listviewtable'] td:nth-child(2)").css("background-color", "red");

I am currently using that to change the background color of a column in SharePoint. 我目前正在使用它来更改SharePoint中列的背景颜色。 Cna some one tell me how to change the font color? cna有人告诉我如何更改字体颜色?

I tried 我试过了

.css("font-color", "red"); 

and

css("text-color", "red");

Both did not work 两者都不起作用

The correct css property for coloring the text on an element is color . 用于为元素上的文本着色的正确的css属性是color

So in your case: .css("color", "red"); 因此,在您的情况下: .css("color", "red");

Color is the correct property to change the text color. 颜色是更改文本颜色的正确属性。 you can test by running the following in your browsers console. 您可以通过在浏览器控制台中运行以下命令进行测试。

$("p").css("color", "red");

see how the text changes color on this page. 在此页面上查看文本如何更改颜色。

If it is not working it is more likely an issue with your selectors. 如果它不起作用,则很可能是您的选择器出现了问题。 Also you can easily simplify your other selector by doing the following 您还可以通过以下操作轻松简化其他选择器

$("table.ms-listviewtable td:nth-child(2)")

This method can take either a property name and value as separate parameters, or a single object of key-value pairs. 此方法可以将属性名称和值作为单独的参数,也可以采用键-值对的单个对象。

So you can use either .css('color','#FF0000'); 因此,您可以使用.css('color','#FF0000'); or .css({'color':'#FF0000'}); .css({'color':'#FF0000'});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM