我希望在一個輸入中有多個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'年初,注意'}'後'其他{...} '。 –