如何更改包含文本的框,以便它只有颜色?

时间:2016-05-11 11:18:51

标签: javascript jquery css text

我目前正在制作一个连接四个游戏,我被建议使用一些我以前用过的现有代码,然后穿过游戏。

我遇到的问题是试图改变颜色并交叉成颜色。我目前的代码是(http://pastebin.com/AkCBLnmt)。我想将x更改为绿色,将o更改为红色。

我尝试了以下但是它没有工作:

$(this).colour("Red");

$(this).colour("Green");

有人可以告诉我如何将文字(x& o)更改为红色和绿色。

由于

5 个答案:

答案 0 :(得分:1)

试试这个

setTimeout(function(){
  d3.select('#count')  
  .html("Head count: 10; Updated");
},500);

请记住,该代码(通常)更喜欢美式拼写。

如果这对您不起作用,您可以发布随附的HTML吗?

答案 1 :(得分:0)

您可以尝试更改文字的颜色:

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

答案 2 :(得分:0)

使用jquery.css()更改样式,如下所示:

$(this).css({'color':'red'});
$(this).css({'color':'green'});

对于想要更改的更多样式,U可以使用

$(this).css({'color':'red','display':'block','margin':'10px'});...

答案 3 :(得分:0)

如果要更改背景颜色

$(this).css('background-color', 'red');

如果要更改文字颜色

$(this).css('color', 'red');

答案 4 :(得分:0)

这样的东西?

$('.colours').each(function(){
 if($(this).text() == 'x') {
  $(this).css('color','green');
 }else{
  $(this).css('color','red');
 }
});