目前,我将网站作为我的个人项目。我已经测试了我的 javascript,它在 chrome 和 firefox 上都可以正常工作。但是当我在 IE 中测试它时,只有部分代码有效。奇怪的是,当我按 f12 并打开开发者工具时,代码运行完美!工作就像它应该做的那样,没有任何错误。
这是我的javascript:
var state_Clicked = false;
var List = document.createElement("div");
function gearClick() {
if(state_Clicked == true) {
List.parentNode.removeChild(List);
state_Clicked = false;
} else {
List.setAttribute("id", "containBox");
List.setAttribute("class", "bgChooserBox");
List.innerHTML = '<span class="thumback"><img onMouseDown="changeBackground(\'RD1_SlurpyNom.jpg\');" class="thumb" src="GRAPHICS/bg/RD1_SlurpyNom.jpg" width="100" height="100" /></span> \
<span class="thumback"><img onMouseDown="changeBackground(\'FS1_SlurpyNom.jpg\');" class="thumb" src="GRAPHICS/bg/FS1_SlurpyNom.jpg" width="100" height="100" /></span> \
<span class="thumback"><img onMouseDown="changeBackground(\'AJ1_SlurpyNom.png\');" class="thumb" src="GRAPHICS/bg/AJ1_SlurpyNom.png" width="100" height="100" /></span> \
<span class="thumback"><img onMouseDown="changeBackground(\'PP1_SlurpyNom.png\');" class="thumb" src="GRAPHICS/bg/PP1_SlurpyNom.png" width="100" height="100" /></span> \
<span class="thumback"><img onMouseDown="changeBackground(\'R1_SlurpyNom.jpg\');" class="thumb" src="GRAPHICS/bg/R1_SlurpyNom.jpg" width="100" height="100" /></span> \
<span class="thumback"><img onMouseDown="changeBackground(\'TS1_SlurpyNom.jpg\');" class="thumb" src="GRAPHICS/bg/TS1_SlurpyNom.jpg" width="100" height="100" /></span> ';
document.getElementsByTagName("body").item(0).appendChild(List);
state_Clicked = true;
}
}
function changeBackground(name) {
console.log('/GRAPHICS/bg/' + name);
document.getElementById("body").style.backgroundImage = 'url(/GRAPHICS/bg/' + name + ')';
document.getElementById("logo").style.opacity = '0.4';
}
任何帮助将不胜感激。