以下代码正常工作,但是我无法弄清楚的一个小问题是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>