简体   繁体   English

如何使输入不区分大小写

[英]How to make an input not case sensitive

I want to know how make it when the user types in something to an input it doesn't have to be the same capitalization as the value for the document.getElementById("spanId").innerHTML = "146.5 meters";我想知道当用户在输入中输入内容时如何使其不必与document.getElementById("spanId").innerHTML = "146.5 meters";的值相同大小写document.getElementById("spanId").innerHTML = "146.5 meters"; to appear.出现。

HTML 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 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";
    }
}

First , use value instead of innerHTML for input fields首先,对输入字段使用value而不是innerHTML

Second , convert both side lowercase or uppercase during comparing其次,在比较时转换两边的小写大写

Try like this像这样尝试

var ask=document.getElementById("ask").value.toLowerCase();
if (ask =="how tall are the pyramids")

Or like this或者像这样

var ask=document.getElementById("ask").value.toUpperCase();
if (ask =="how tall are the pyramids".toUpperCase())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM