사용자 이름을 저장하고 콘솔에 인쇄되는 배열을 만들려고합니다. 그러나 페이지를 새로 고침하고 제출을 누르면 마지막 사용자 이름이 표시되지 않습니다. 나는 의미있는 변수 이름을 가지고있다 처음있는 코드와 몇 가지 문제가 있다고 생각로컬 저장소가 작동하지 않는 이유는 무엇입니까?
var users = [];
function User(first_name, last_name, username, password, email, birthday_month, birthday, birthday_year){
this.first_name = first_name;
this.last_name = last_name;
this.username = username;
this.password = password;
this.email = email;
this.birthday_month = birthday_month;
this.birhday = birthday;
this.birthday_year = birthday_year;
}
var Msg = document.getElementById("Msg");
function Submit(){
var a = document.forms["form"]["First_Name"].value;
var b = document.forms["form"]["Last_Name"].value;
var c = document.forms["form"]["Username"].value;
var d = document.forms["form"]["Password"].value;
var l = document.forms["form"]["Email"].value;
var month = document.forms["form"]["birthday_month"].value;
var day = document.forms["form"]["birthday"].value;
var year = document.forms["form"]["birthday_year"].value;
localStorage.setItem("fn", a);
var ln = localStorage.b;
var u = localStorage.c;
var p = localStorage.d;
var e = localStorage.l;
var m = localStorage.month;
var d = localStorage.day;
var y = localStorage.year;
if (ln == null || ln == "" || u == "" || u == null || p == "" || p == null || e == null || e == "" || m == "Month" || d == "Day" || y == "Year") {
Msg.textContent = "Please fill out all information correctly!";
return false;
} else {
var account = new User(ln, u, p, e, m, d, y);
var wha = localStorage.getItem("fn");
users.push(wha);
Msg.textContent = "Registration succesful!"
console.log(users);
}
}
HTML을 게시 할 수 있습니까? 문제를 진단 할 수 있도록 스 니펫을 만드십시오! – FrankerZ
가능한 [변수를 사용하여 동적으로 개체 속성에 액세스] (0120-558-005) –