我想知道当用户输入某个输入时它是如何制作的,它不必与显示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";
}
}
答案 0 :(得分:1)
首先,使用value
代替innerHTML
作为输入字段
第二,在比较期间转换小写或大写
试试这个
var ask=document.getElementById("ask").value.toLowerCase();
if (ask =="how tall are the pyramids")
或者像这样
var ask=document.getElementById("ask").value.toUpperCase();
if (ask =="how tall are the pyramids".toUpperCase())