我成功地使用 html en javascript 创建了一个用户登录表单。用户可以注册和登录。但是我需要在用户登录时设置一个类,以便他们可以看到自定义导航。我的html代码如下:`account_circle
</div>
</div>
<div class="row margin">
<div class="input-field col s12">
<i class="mdi-social-person-outline prefix"></i>
<input id="logname" type="text">
<label for="logname" >Username</label>
</div>
</div>
<div class="row margin">
<div class="input-field col s12">
<i class="mdi-action-lock-outline prefix"></i>
<input id="logpw" type="password">
<label for="logpw">Password</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<div class="center-align"><a id="login_btn" class="btn waves-effect waves-light" type="submit" onclick="check()">Login</a></div>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<div class="center-align"><a href="register.html" class="btn waves-effect waves-light">Registreer hier</a></div>
</div>
</div>
</form>`
$(document).ready(function(){
$(".button-collapse").sideNav();
});
// naam en pas register
var regiName = document.getElementById('regname');
var regiPw = document.getElementById('regpw');
function store() {
localStorage.setItem('uName', regiName.value);
localStorage.setItem('pw', regiPw.value);
}
function check() {
var storedName = localStorage.getItem('uName');
var storedPw = localStorage.getItem('pw');
var userName = document.getElementById('logname');
var userPw = document.getElementById('logpw');
if(userName.value == storedName && userPw.value == storedPw) {
alert('You are loged in.');
}else {
alert('Gebruiker of wachtwoord wordt niet herkend.' + userName);
}
}