小编Ash*_*nto的帖子

如何执行不区分大小写的字符串比较?

我的网站上有一个文本框,用户可以输入命令.但问题是命令区分大小写.如何使命令不区分大小写?这是我的代码:

JavaScript的:

function showAlert() {

    var txtCtrl = document.getElementById("textbox1");

    var txtVal = txtCtrl.value;

    if (txtVal == '') {
        alert('Please fill in the text box. For a list of commands type "Help" into the text box.');
    }else if (txtVal == 'Start' || txtVal == 'start') {
        alert('Hello. What would you like me to do?');
    }else if (txtVal === 'Weather' || txtVal === 'weather') {
        window.location = "https://www.google.com/#q=weather";
    }else if (txtVal === 'Time' || txtVal === 'time') {
        alert('The current time according …
Run Code Online (Sandbox Code Playgroud)

javascript

4
推荐指数
2
解决办法
3万
查看次数

标签 统计

javascript ×1