我希望在一个输入中有多个if-else
语句,当我使用此代码时,只有how tall is the gateway arch
会得到警报而不是how tall are the pyramids
。如何有一个以上的语句在JavaScript中的输入
这有可能吗?
document.getElementById("button").onclick = function() {
if (document.getElementById("ask").value == "how tall are the pyramids") {
alert("146.5 meters");
} else {
alert("How should I know");
}
}
if (document.getElementById("ask").value == "how tall is the gateway arch") {
alert("630 feet");
} else {
alert("How should I know");
}
}
您关闭'onclick'年初,注意'}'后'其他{...} '。 –