-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' –
这是一个愚蠢的问题,但你将如何分配一个变量 –