14 번째 줄과 28 번째 줄에서는 label 태그의 텍스트가 변경되지 않고 recorForm 또는 loginSetup에서 데이터를 덮어 씁니다. .key
을 사용하여 루프를 시도했지만 잘못 저장된 결과가 출력되었고 내가 잘못했는지 확실하지 않습니다.
그래서 나는 이것을 남겨두고있다. 라벨의 innHTML이 변경되지 않습니다 이유를 알고 싶은 무엇
이다. (나는 가정이로드로 인해입니다)localStorage 덮어 쓰기/innerHTML 오류
window.onload = alert('Window Loaded');
function recordForm() {
var userMail = document.getElementById('email').value;
var userPass = document.getElementById('password').value;
var confirm = document.getElementById('confirmation').value;
var text = document.getElemetsByClassName('errorText');
//Check that the email is not taken and confirm validation
if ((userPass === confirm)) {
localStorage.setItem('emailz', userMail.value);
localStorage.setItem('passwordz', userPass.value);
} else {
text.innerHTML = 'Password does not match!'; //line 14
}
}
function loginSetup() {
var mail = localStorage.getItem('emailz');
var pass = localStorage.getItem('passwordz');
var mailInput = document.getElementById('logEmail').value;
var passInput = document.getElementById('logPassword').value;
if ((mailInput === mail) && (passInput === pass)) {
alert(mail);
alert(pass);
} else {
text.innerHTML = 'Invalid login'; //line 28
alert('no dice');
alert(mail);
alert(pass);
}
}
관련 HTML도 게시하십시오. 또한,'alert' 행을 모두'console.log'로 바꾸십시오. 그러면 UI가 차단되지 않고 부작용이 생기지 않습니다. –
userMail 및 userPass는 localStorage에 값을 쓰는 동안 가치가 없습니다. – Lain
개발자 도구에서 콘솔을 엽니 다. 오류 메시지를 읽으십시오. 처음에는 기능 이름을 잘못 입력했습니다. – Quentin