【发布时间】:2020-05-21 19:01:13
【问题描述】:
我有这个小代码来使用需要包含各种字符串的密钥进行登录...但是 .includes 方法始终是正确的,有人可以解释我有什么问题吗?
function validate() {
var keyInput = document.getElementById("keyInputBox").value;
console.log('User trying to log with key: "' + keyInput + '"');
var keyRequireBoolean0 = keyInput.includes('anon')
if (keyRequireBoolean0 = true) {
var keyRequireBoolean1 = keyInput.includes('sup')
if (keyRequireBoolean1 = true) {
alert('login successfull ' + keyRequireBoolean0)
} else {
alert('Invaild Key');
}
} else {
alert('Invaild Key');
}}
这是html部分:
<input type="password" id="keyInputBox" placeholder="Key">
<input type="submit" onclick="validate()" value="Check">
【问题讨论】:
-
keyRequireBoolean0 = true设置为true,改为使用==进行比较。 -
UHHHHHHH 是的,我忘了添加另一个 =
-
你什么都不需要,只要
if(keyRequireBoolean0)
标签: javascript html include