1. 从网上下载jquery.cookie.js,拷贝到应用程序中。
2. 登录页面(login.jsp)导入jquery.cookie.js
<script type="text/javascript">
$(function(){
var n = $.cookie(‘username‘);
var p = $.cookie(‘password‘);
$("#username").val(n);
$("#password").val(p);
$(‘#cookiePwd‘).click(function(){
if($(this).attr(‘checked‘)){
$(‘#cookieInfo‘).attr(‘checked‘, true);
}
});
$("#btn").click(function(){
var n = $("#username").val().trim();
var p = $("#password").val().trim();
if($(‘#cookiePwd‘).attr(‘checked‘)){
$.cookie(‘username‘, n, {expires:7});
$.cookie(‘password‘, p, {expires:7});
}else{
$.cookie(‘username‘, null);
$.cookie(‘password‘, null);
}
});
});
</script>
<div class="login-wrapper">
<div class="login-area dib-m">
<form action="login.do" method="post" id="" name="" class="form">
<div id=‘btn_warning‘ class="bug-text" style="display: none;"></div>
<div class="user textbox"><input type="text" id="username" name="username" value="" placeholder="请输入用户名" ></div>
<div id=‘user_warning‘class="bug-text"></div>
<div class="pass textbox"><input type="password" id="password" name="password" value="" placeholder="请输入密码"></div>
<div id=‘pass_warning‘ class="bug-text"></div>
<div class="btn">
<input type="button" class="login-btn dib-m" id="btn" value="登 录">
<label class="dib-m">
<em class="c9">记住密码</em>
<input type="checkbox" checked class="checkbox checkbox-animbg dib-m" id="cookiePwd" ></label>
</div>
</form>
</div>
<div class="dib-m h"></div>
</div>