我有改变背景的颜色。现在如何更改文本的颜色?

问题描述 投票:0回答:1

我是这里的新手,这是我的第一个问题。

每次浏览器刷新时,我的网站背景都会按顺序更改颜色,这很好(是)。

现在我还想更改与我的身体关联的字体颜色属性,因此每次刷新时我都可以使用不同的页面主题。

例如,刷新时:

带有蓝色文本的红色背景,然后带有绿色文本的橙色背景,等等。>>

任何想法如何优雅地将其添加到我现有的代码中?

我试图复制我的代码并以color属性(而不是background-color)为目标,只是看它是否可以工作,而不能。

谢谢您的帮助!

function loadNextImage1() {

  //declare image directory path and image array
  var colors = ["#red", "#blue", "#green"];
  colors[0] = "#red";
  colors[1] = "#blue";
  colors[2] = "#green";

  //get current cookie value
  var currentIndex = parseInt(getCookie());
  var background = colors[currentIndex];

  document.body.style.backgroundColor = background;

  //set next cookie index
  currentIndex += 1;
  currentIndex %= colors.length;
  setCookie(currentIndex);
}

function setCookie(someint) {
  var now = new Date();
  var addDays = now.getDate() + 7
  now.setDate(addDays); // cookie expires in 7 days
  var theString = 'imgID=' + escape(someint) + ';expires=' + now.toUTCString();
  document.cookie = theString;
}

function getCookie() {
  var output = "0";
  if (document.cookie.length > 0) {
    var temp = unescape(document.cookie);
    temp = temp.split(';');
    for (var i = 0; i < temp.length; i++) {
      if (temp[i].indexOf('imgID') != -1) {
        temp = temp[i].split('=');
        output = temp.pop();
        break;
      }
    }
  }
  return output;
}
<body onload="loadNextImage1();">
  <img id="ImageRefresh"/>
</body>

我是这里的新手,这是我的第一个问题。我的网站背景是每次浏览器刷新时都会按顺序更改颜色,这很好(是)。现在我也想更改...

javascript
1个回答
0
投票

您可以有2套合计为您的组合

© www.soinside.com 2019 - 2024. All rights reserved.