2016-12-28 72 views
1

如何在我的代碼中添加檢查以使參數變量不區分大小寫?我希望用戶能夠輸入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; 
} 

回答

5

你可以將其轉換爲小寫和比較:

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

謝謝你,並沒有意識到這將是簡單 –

相關問題