javascript - 如何使用大写/小写
问题描述
嘿所以我有一个这样的代码
const answer = "HA"
const answers = answer.toLowerCase();
const theanswer = document.getElementById("WIT").value;
if(theanswer == answers) {
console.log("correct")
}
问题是只有当我输入“ha”时才会出现正确的
如果我输入“HA”或“Ha”或“hA”或“ha”,我怎样才能做出正确的显示
解决方案
要比较这些值 - 也将值转换为小写 - 例如 - 尝试在输入中键入“ha”。
在第一个字符 - “h” - 您将记录“h:不正确”,然后在“a”上记录“ha:正确”。任何其他字符 s 显然与“HA”不匹配,并且是不正确的。
const answer = "HA"
const answers = answer.toLowerCase();
document.querySelector('#WIT').addEventListener('keyup', checkMe)
function checkMe(){
const theanswer = document.getElementById("WIT").value;
if(theanswer.toLowerCase() == answers) {
console.log(theanswer + ": correct")
} else {
console.log(theanswer + ": incorrect")
}
}
<input type="text" id="WIT" />
推荐阅读
- android - 是否可以在 AndroidStudio 中使用 nidi.guru Graphviz 实现?
- android - Amazon Pinpoint 和 Ionic - 当应用程序处于后台时,推送通知不起作用
- excel - 如果满足条件,则添加条件的 Excel Sumifs
- python - 如何上传和比较列表?
- c# - MVVM 从 TabControl 绑定到 Page.DataContext
- javascript - 在子transitionend上触发Transitionend
- python - Keras 批量标准化 - 什么轴?
- php - 从给定的mysql结果中获取月数
- actionscript-3 - 我正在尝试让一个 MovieClip 跟随另一个 MovieClip 直到联系。一个影片剪辑按加速度计移动
- java - 在这种情况下,Java Queue 无法存储 Integer