如何使用localStorage中阵列的详细信息成功登录



一旦uninputpwinput与LocalStorage中的数组匹配,如何停止循环?

function login() {
existinglist = JSON.parse(localStorage["existinglist"]);
var uninput = document.getElementById('UserName').value;
var pwinput = document.getElementById('PassWord').value;
for (var i = 0; i < existinglist.length; i++) {
if (uninput == existinglist[i]['UserName'] && pwinput == existinglist[i]['Password']) {
credential
alert('You have login successfully!');
break;
} else {
alert('Invalid login!');
}
}
}
<form action="             " class="loginform" onsubmit=' return login()'>
<label>Username: </label>
<input type="text" id='UserName' name="UserName" autocomplete='off' required>
<label>Password: </label>
<input type="password" id='PassWord' name="PassWord" autocomplete='off' required>
<button type="submit">Log in</button>
</form>

用于创建用户帐户的第二个页面不存在。你的代码会起作用,前提是它在一个函数中,并且你删除了那些标签

相关内容

最新更新