不知道怎么写注册的可以看一下我的另一篇账号注册
css:
*{ padding:0; margin:0; } #q{ width: 35%; height: 300px; background-color: aqua; margin-top: 200px; margin-left: 28%; } #w{ text-align: center; font-size: 30px; line-height: 60px; } #e{ width: 200px; height: 25px; } #r{ width: 200px; height: 25px; } .t{ margin-top: 30px; text-align: center; display: flex; justify-content: space-around; align-items: center; } #y{ color: crimson; font-size: 30px; padding-top: 20px; padding-left: 13px; margin-left: 70%; width: 80px; height: 60px; background-color: azure; } .box{ padding-right: 30px; font-size: 30px; } .boc{ padding-right: 30px; font-size: 30px; }
html:
<div id="q"> <p id="w">登录</p> <div class="t"> <span class="box">账号:</span> <input type="text" id="e"> </div> <div class="t"> <span class="boc">密码:</span> <input type="password" id="r"> </div> <div id="y" onclick="piuisc()">登录</div> </div>
js:
function piuisc(){ let data = localStorage.getItem("data") == null ? [] : JSON.parse(localStorage.getItem("data")); let tyui = false; let a = document.getElementById('e').value; let b = document.getElementById('r').value; for(let i = 0; i < data.length ; i++){ if (a == data[i].a && b == data[i].b) { tyui = true; }else{ tyui = false; } } if(tyui == true){ alert('登陆成功'); }else{ alert('登陆失败'); } }
1.点击获取到value值
2.循环判断账号和密码本地储存里是否拥有
3.根据返回的值再判断弹出的是什么(如果直接返还将会循环弹出)