-1
我想知道如何使用戶輸入某些內容時,如果輸入的內容不必與document.getElementById("spanId").innerHTML = "146.5 meters";
出現的值相同。如何使輸入不區分大小寫
HTML
<input id="ask" type="text"
placeholder = "Ex: how tall is the Gateway Arch"
onfocus="this.placeholder = ''"
onblur="this.placeholder = 'Ex: how tall is the gateway arch'"
text-align: center/>
JS
document.getElementById("button").onclick = function() {
if (document.getElementById("ask").innerHTML == "how tall are the pyramids") {
document.getElementById("spanId").innerHTML = "146.5 meters";
} else if (document.getElementById("ask").value == "how tall is the gateway arch") {
document.getElementById("spanId").innerHTML = "630 feet";
} else if (document.getElementById("ask").value == "how tall is the empire state building") {
document.getElementById("spanId").innerHTML = "1,454 feet";
}
}
這將只對如果else語句不是別人 –
工作分配給它一個變量在任何需要的地方使用該變量而不是每次使用'document.getElementById(「ask」).value' –
這是一個愚蠢的問題,但你將如何分配一個變量 –