无法从输入字段获取数据,复选框并将其存储在localStorage中。请让我知道如何调试它。这是codepen http://codepen.io/coden/pen/vKaAAv 和JS代码是
function User(name, email) {
this.name = name;
this.email = email;
this.tesla = tesla.checked;
this.leaf = leaf.checked;
this.bmw = bmw.checked;
};
var user_name = event.target.user_name.value
var newUser = new User(user_name, user_email);
function getUserData() {
event.preventDefault ();
var user_name = event.target.user_name.value
var user_email = event.target.user_email.value;
var newUser = new User(user_name, user_email);
console.log (newUser);
localStorage.setItem('userProfile', JSON.stringify(newUser));
}
var personInfo = document.getElementById('personinfo')
personInfo.addEventListener ("submit", getUserData);