>用户将"足球"写入我的输入栏中,然后执行第 6 行和第 7 行的操作。
但是,如果用户用大写字母写"足球"怎么办? 我试图实现"逻辑或"||但我无法让它工作。
var input = document.getElementById("user_input");
let footballTeams = ["Manchester","Barcelona","Copenhagen"]
if (input.value == "football") {
alert("These cities have football teams:" +
"n" + footballTeams[0] + "," + " " + footballTeams[1] + "," + " " + footballTeams[2])
试试这个:
if (input.value.toLowerCase() == "football")
尝试
if (input.value.toLowerCase() == "football") {
console.log('inside if');
}
<input id=input value="Football">