Javascript更改身体背景图像和页脚背景图像

时间:2014-05-07 21:01:19

标签: javascript css

以下代码正常工作,但是我无法弄清楚的一个小问题是backImage是要更改背景图像的图像而ftImage是用于更改图像的图像页脚正在更改背景图像,但不会更改css文件中类#footer的页脚背景。

任何帮助将不胜感激......

<script language="JavaScript">
var backImage = new Array();
var ftImage = new Array();
var myElement = document.querySelector("#footer");

backImage[0] = "images/patterns/yellow.png";
ftImage[0] = "images/patterns/blue.png";
backImage[1] = "images/patterns/blue.png";
backImage[2] = "images/patterns/green.png";
backImage[3] = "images/patterns/brown.png";
backImage[4] = "images/patterns/grey.png";
backImage[5] = "images/patterns/red.png";
function changeBGImage(whichImage){
  if (document.body){
    var footer = document.querySelector("#footer");
   document.body.style.backgroundImage = "url("+backImage[whichImage]+")";
   //myElement.style.backgroundImage = "url("+ftImage[whichImage]+")";
   footer.style.backgroundImage = "url("+ftImage[whichImage]+")";
   cookie.set('bgImage', whichImage, 365);
}}
</script>

0 个答案:

没有答案