区分大小写检查查询参数?

时间:2016-12-28 20:49:44

标签: javascript

如何在代码中添加检查以使参数变量不区分大小写?我希望用户能够输入ab = ac作为查询参数或AB = AC或aB = aC以及任何其他变体。我的代码如下。根据现有参数,headOne或headTwo将显示在页面上。

 myObject: function() {
    var parameter = window.location.search.includes("ab=ac");
    var headOne = data.headerOne;
    var headTwo = data.headerTwo;
    var helpers = _.extend(this.constructor.__super__.myObject.call(this), {
        header: parameter ? headerOne : headerTwo
    });
    return helpers;
}

1 个答案:

答案 0 :(得分:5)

您可以将其转换为小写并进行比较:

var parameter = window.location.search.toLowerCase().includes("ab=ac");
//------------------------------------^^^^^^^^^^^^^^