button.onclick = () => {
if (document.querySelector('input[name="username"]').value === 'admin' &&
document.querySelector('input[name="password"]').value === 'admin') {
// 跳转到admin.html
window.location.href = './admin.html';
} else {
fetch('./up.json')
.then(response => response.json())
.then(data => {
let loginSuccess = false;
data.forEach(item => {
if (item.username === document.querySelector('input[name="username"]').value &&
item.password === document.querySelector('input[name="password"]').value) {
loginSuccess = true;
}
});
if (loginSuccess) {
// 跳转到user.html
alert('登录成功!');
window.location.href = './user.html';
} else {
alert('登录失败!');
}
});
}
}
这段遍历json文件然后检测的代码用不了,admin正常,但是后面那段无法运行
打印下data,看看是什么数据咯
【相关推荐】