javascript - 如果输入 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])
解决方案
尝试这个:
if (input.value.toLowerCase() == "football")
推荐阅读
- c - 如何在c中的char数组中保存命令的输出?
- powershell - 使用 PowerShell 查询 GraphQL
- python-3.x - 将新创建的文件夹的名称放在 csv 文件的路径中
- python - Python 3 - 如何在 Python 中处理和读取表情符号和 unicode?一个测试
- nginx - 将所有案例重定向到 https 和非 www 时,Nginx 重定向不起作用
- node.js - 什么时候使用集群或 worker_threads 更好?
- swift - 在两个函数之间传递变量
- r - 从数据框中删除一列中具有无限值的行,而不是其他列
- django - 错误:与 redux 一起使用时挂钩调用无效
- flutter - 过滤并从'地图中获取新地图
飞镖中的 myMap'