Javascript JS设置字体颜色
我正在用JavaScript制作一个游戏,我想改变文本的颜色 这是代码的一部分:Javascript JS设置字体颜色,javascript,Javascript,我正在用JavaScript制作一个游戏,我想改变文本的颜色 这是代码的一部分: if (game.active) { this.damageCountry(otherLost, country); } battle.sendMessage("You have failed to " + game.normalizeCountryName(country) + " conquer", "<em>" + game.normalizeCountryName(c
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());
这将使字体颜色变为红色。随意改变
这将使用jQuery$.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());
battle.sendMessage(“您未能”+
游戏。国家名+征服“,
“+game.normalizeCountryName(国家)+”的损失:”+
Math.round(otherLost.commafy()+“您的损失:”+
Math.round(lost.commafy());
加:
“文本…”
if中的几乎所有内容。@Sebas我们不知道您要更改的文本颜色是什么意思?this.sendMessage=function(title,message){$(“.top message”).show();$(“.top message>h1”).first().html(title);$(“.top message>p”).first().html(message);this.title=title;this.message=message;@vihan1086我想改变战斗的颜色。sendMessage@Sebas我们能看到战斗的代码吗?sendMessage
如果我想对不同的行使用多种颜色吗?@Sebas,上面写着“红色”
更改颜色。你可以对不同的行使用不同的颜色。我会更新我的现在回答,如果我想给“game.normalizeCountryName(country)”一个颜色,它会显示一个国家。@Sebas我把它改成红色,如果我在游戏中使用span,请随意更改颜色。normalizeCountryName(country)游戏不再运行。
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;
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());
"<span style=\"color: YOUR_COLOR;\">Text...</span>"