为何输入的数据不能存储或追加在本地存储中
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
label{
width:50px;
display:inline-block;
text-align:left;
}
form{
width:260px;
height:100px;
background-color:aqua;
text-align:center;
}
</style>
</head>
<body>
<h1>试试看,能否登入自己qq</h1>
<form action="#" method="get">
<label>qq:</label><input type="text" name="usname" placeholder="请输入qq号" class="iptone" >
<label>密码:</label><input type="password" placeholder="请输入密码" name="password" class="ipttwo" >
<input type="submit"value="登录" class="submit">
</form>
<ul class="ulul">
</ul>
</body>
<script>
constiptone=document.querySelector('.iptone');
constipttwo=document.querySelector('.ipttwo');
const submit=document.querySelector('.submit');
const ulul=document.querySelector('ulul');
submit.addEventListener('click',function(){
vardatao= iptone.value;
vardatat=ipttwo.value;
var dataall=datao+'+'+datat;
var local=getdata();
local.push(dataall);
savadate(local);
})
function getdata(){
var data=localStorage.getItem('usename');
if(data!==null){
return JSON.parse(data);
}
else{
return [];
}
}
function savadate(data){
loaclStorage.setItem('usename',JSON.stringify(data));
}
</script>
</html>
你这个登录按钮是个submit类型的,点击时是向#发起get请求,这时会发生一个页面跳转。。。其次,你的savadate方法的localStorage写成了loaclStorage。所以会报错,你应该是因为页面跳转,所以没看到报错信息。。。。
页:
[1]