如果状态不区分大小写,如何制作多个

时间:2015-09-06 04:33:09

标签: html input

每当我将一个to.LowerCase添加到else if语句时,它会导致整个语句不起作用。修复任何人?

document.getElementById("button").onclick=function() {

    ///monuments

        var ask=document.getElementById("ask").value.toLowerCase(); ;
        if (ask =="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";

1 个答案:

答案 0 :(得分:1)

分配后,您无需再次使用document.getElementById("ask").value来询问

试试这个

var ask = document.getElementById("ask").value.toLowerCase();
var info = "";
if (ask == "how tall are the pyramids") {
    info = "146.5 meters";
} else if (ask == "how tall is the gateway arch") {
    info = "630 feet";
}
document.getElementById("spanId").innerHTML = info