[英]JS set font color
I'm making a game in JavaScript and I want to change te text color.我正在用 JavaScript 制作游戏,我想更改文本颜色。
This is a part of the code:这是代码的一部分:
if (game.active) {
this.damageCountry(otherLost, country);
}
battle.sendMessage("You have failed to " +
game.normalizeCountryName(country) + " conquer",
"<em>" + game.normalizeCountryName(country) + "'s losses: </em>"+
Math.round(otherLost).commafy() + "</br><em>your losses: </em>" +
Math.round(lost).commafy());
I want to change the text color of battle.sendMessage.我想更改 Battle.sendMessage 的文本颜色。
this.sendMessage = function(title, message){
$(".battle").show();
$(".battle>h1").first().html(title);
$(".battle>p").first().html(message);
this.title = title;
this.message = message;
this.sendMessage = function(title, message){
$(".top-message").show();
$(".top-message>h1").first().html(title).css('color', 'red');
$(".top-message>p").first().html(message).css('color', 'red');
this.title = title;
this.message = message;
This will make the font-color
red.这将使
font-color
变为红色。 Change as you would like.随心所欲地改变。
$.fn.css()
learn more here
$.fn.css()
在此处了解更多信息
battle.sendMessage("You have failed to <span style=\\"color:red\\">" + game.normalizeCountryName(country) + "</span> conquer", "<em>" + game.normalizeCountryName(country) + "'s losses: </em>"+ Math.round(otherLost).commafy() + "</br><em>your losses: </em>" + Math.round(lost).commafy());
Add:添加:
"<span style=\\"color: YOUR_COLOR;\\">Text...</span>"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.