嗨,我需要將文本輸入和數組轉換爲小寫,所以輸入時它可以匹配數組。我不斷收到錯誤,表示airline.Array.contains不是一個函數。任何人都可以幫忙嗎?隱藏輸入爲小寫
var euAirlines = [
"British Airways",
"Austrian Airlines",
"Blue Islands",
"KLM",
"TAP Portugal",
"Air Malta",
"Air France",
"germanwings",
"Wideroe",
"Lufthansa",
"Aegean Airlines",
"Citywing",
"Flybe",
"Aurigny",
"airBaltic",
"Swiss",
"eurowings",
"Croatia Airlines",
"SAS",
"LOT",
"Air Serbia",
"Iberia",
"Wizz Air",
"Blue Air",
"easyJet",
"Air Europa",
"Czech Airlines",
"Aer Lingus",
"Eastern Airways",
"Smart Wings",
"Aeroflot",
"Thomson Airways",
"bmi regional",
"Ryanair",
"Monarch",
"TAROM",
"Brussels Airlines",
"Jet2",
"Meridiana",
"Vueling Airlines",
"CityJet",
"Scilly Skybus",
"Alitalia",
"Thomas Cook Airlines",
"Garuda Indonesia",
"Norwegian",
"Ukraine International",
"Bulgaria Air",
"Finnair",
"Luxair"
];
Array.prototype.contains = function (needle) {
for (i in this) {
if (this[i] == needle) return true;
}
return false;
}
var airlineInput = document.getElementById("airlineInput"),
airlineArray = euAirlines.toString().toLowerCase();
document.getElementById("claim-submit").onclick = function(e) {
var lower = airlineInput.value.toLowerCase();
console.log(lower);
if (airlineArray.contains(lower.value)) {
console.log("Match");
}else {
console.log("No Match")
}
}
這是因爲它不是一個數組...'airlineArray = euAirlines.toString()toLowerCase();'不做你的想法 –
airlineArray我想所有的數組值都是小寫,然後檢查文本輸入。 – Doddsy
在'toLowerCase()'後添加'.split(',')''''''' –