我正在尝试开发一个具有自定义背景的网站。但背景不起作用。
这是代码
<html>
<head>
<title>Custom background</title>
<link rel="shortcut icon" type="image/x-icon" href="https://goo.gl/b8xuMH">
</head>
<body>
<script>
var a = prompt("What Do You Like (Capitalize All Words) (Type In List To Show List)");
if (a === "List") {
confirm("Cars,");
var a = prompt("What Do You Like (Capitalize All Words) (Type In List To Show List)");
}
if (a === "Cars") {
var b = prompt("What Type (Capitalize All Words) (Type In “List” To Show List)");
} else {
confirm("did not understand");
}
if (b === "List") {
confirm("Sports Cars,");
var b = prompt("What Type (Capitalize All Words) (Type In “List” To Show List)");
}
if (b === "Sports Cars") {
var c = prompt("What Company (Capitalize All Words)(Type In List To Show List)");
} else {
confirm("did not understand");
}
if (c === "List") {
confirm("Bocar,");
var c = prompt("What U.S.A. Company (Capitalize All Words) (Type In List To Show List)");
}
if (c === "Bocar") {
var d = prompt("What Model (Capitalize All Words) (Type In List To Show List)");
}
if (d === "List") {
confirm("Stiletto,");
var d = prompt("What Model (Capitalize All Words) (Type In List To Show List)");
}
if (d === "Stiletto, Xp-4") {
document.body.style.backgroundImage = "url('http://goo.gl/l8Pjl8')";
} else if (d === "Xp-4") {
document.body.style.backgroundImage = "url('http://goo.gl/CEHZ4N')";
}
</script>
</body>
</html>
指导我解决这个问题。
答案 0 :(得分:0)
你的最后一个if和else if块的条件永远不会满足。我建议编辑这些条件并添加else
语句,这样如果没有满足任何条件,它将显示至少一些其他图像
if (d === "Stiletto, Xp-4") {
document.body.style.backgroundImage = "url('http://goo.gl/l8Pjl8')";
} else if (d === "Xp-4") {
document.body.style.backgroundImage = "url('http://goo.gl/CEHZ4N')";
} else if (d === "Stiletto") {
document.body.style.backgroundImage ="url('some other image')";
} else {
document.body.style.backgroundImage ="url('if no other conditions are met use this')";
}