.includes 方法在 js 中始终为真
.includes method is always true in js
我有这段小代码可以使用需要包含各种字符串的密钥进行登录...但是 .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">
您要做的是比较布尔值:
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');
}}
我有这段小代码可以使用需要包含各种字符串的密钥进行登录...但是 .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">
您要做的是比较布尔值:
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');
}}