我需要在sessionStorage中保留登录状态,但我似乎无法让它工作,有人可以帮我编辑sessionstorage代码以使其工作吗?
下面是我正在努力工作的会话存储脚本的代码。
<head>
<meta name="viewport" content="width=device-width, user-scalable=yes, initialscale=1.0">
<link rel="stylesheet" type="text/css" href="logincss.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="loginjavascript.js"></script>
<script>
$(document).ready(function () {
$('#form').submit(function (event) {
$.post(this.action, $(this).serialize(), function (data) {
alert(data.msg+" "+data.status);
$('#status').html(data.msg);
if (data.status==1){
$('#hide').toggle();
//'Sessionstorage here'
$('login').click(function () {
var name = this.name;
var info = 'div#' + name;
if ($(info).is(':hidden')) {
if (sessionStorage[name]) {
var obj = JSON.parse(sessionStorage[name]);
var div = 'div#' + obj.pid;
$(div).html(item({product: obj}));
}
}
$(info).toggle();
return false;
});
}
}, 'json');
event.preventDefault();
});
});
</script>
</head>
<header class="cf">
<img src="images/badnoise.png" alt="logo" width="199" height="92">
<nav>
<ul>
<li id="login">
<div id="status">Not logged in</div>
<a id="login-trigger" href="#">
Log in <span>▼</span>
</a>
<div id="login-content">
<form id="form" action="login.php">
<fieldset id="inputs">
<input id="username" type="email" name="Email" value="bard@stratford.com" placeholder="Your email address" required />
<input id="password" type="password" name="Password" value="Hamlet34" placeholder="Password" required /><br/>
Password contains at least 1 capital letter. <br/>
Password contains at least 5 lower case letters. <br/>
Password contains at least 1 number.<br/>
Password must be a minimum of 8 characters.
</fieldset>
<fieldset id="actions">
<input type="submit" id="submit1" value="Log in">
<label><input type="checkbox" checked="checked"> Keep me signed in</label>
</fieldset>
</form>
</div><br/>
</li>
</ul>
</nav>
<center><h1><a href="index.php">Artists<a> || <a href="songs.php">Songs</a></h1></center><h1>
</header>
谢谢