我正在用JavaScript制作游戏,我想改变文字颜色。
这是代码的一部分:
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());
我想更改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;
答案 0 :(得分:0)
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;
这会使font-color
变红。根据需要改变。
<小时/> 这使用 jQuery
$.fn.css()
了解详情here
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>"