一旦uninput
和pwinput
与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>
答案 0 :(得分:0)
您创建用户帐户的第二页不存在。您的代码可以正常运行,只要它在函数中并且您删除这些标签即可