首页 > 解决方案 > 如果输入 a 或 b 正确/正确,我该如何执行操作?

问题描述

用户将“足球”写入我的输入栏,然后执行第 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])

标签: javascriptarrayslogical-operators

解决方案


尝试这个:

if (input.value.toLowerCase() == "football")

推荐阅读