<div class="name">
<input type="text" id="value_1" placeholder="用户名" name="value_1" tabindex="1">
<a class="btn" href="javascript:;" style="position:absolute;right:-45px;color:#FFF;width:40px;height:30px;line-height:30px">注册</a>
</div>
<div class="pwd">
<input type="password" id="value_2" placeholder="密码" name="value_2" tabindex="2">
<input type="button" class="submit" tabindex="3">
<div class="check"></div>
</div>比如,添加的记住密码代码为:<div class=remember"><input type="checkbox" name="remember" id="remember" value="记住我的登录信息" /><label for="remember" >下次自动登录</label></div>请问,这样如何能实现登录自动记住登录状态呢?
是否还要后台数据库设置,还是加一段JS代码就可以实现呢?
<input type="text" id="value_1" placeholder="用户名" name="value_1" tabindex="1">
<a class="btn" href="javascript:;" style="position:absolute;right:-45px;color:#FFF;width:40px;height:30px;line-height:30px">注册</a>
</div>
<div class="pwd">
<input type="password" id="value_2" placeholder="密码" name="value_2" tabindex="2">
<input type="button" class="submit" tabindex="3">
<div class="check"></div>
</div>比如,添加的记住密码代码为:<div class=remember"><input type="checkbox" name="remember" id="remember" value="记住我的登录信息" /><label for="remember" >下次自动登录</label></div>请问,这样如何能实现登录自动记住登录状态呢?
是否还要后台数据库设置,还是加一段JS代码就可以实现呢?
下一次的打开这个登陆网页的时候 在onload中线查看cookies中有没有数据 有的话就直接登录 没有的话就显示页面 然后和前面一样 点登陆的时候再设置cookies
<head>
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function () {
//判断cookies是否存在
if (getCookie("cookie_userid") != "" && getCookie("password") != "") {
alert("login success:\nid=" + getCookie("cookie_userid") + " password=" + getCookie("password"));
//转移到登陆成功页面
location.href = "test.html";
} //login按钮的点击处理
$("#login").click(function () {
//获取文本框的userid和password
var userid = $("#userid").val();
var password = $("#password").val();
//设置cookies
setCookie("cookie_userid", userid, 7);
setCookie("cookie_password", password, 7);
});
}); //设置cookies的方法(w3cschool上的简单设置cookie代码,自己可以去搜索下)
//c_name:cookie名称
//value:cookie的值
//expiredays:有效天数
function setCookie(c_name, value, expiredays) {
var exdate = new Date()
exdate.setDate(exdate.getDate() + expiredays)
document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
}
//获取cookies的方法
function getCookie(c_name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=")
if (c_start != -1) {
c_start = c_start + c_name.length + 1
c_end = document.cookie.indexOf(";", c_start)
if (c_end == -1) c_end = document.cookie.length
return unescape(document.cookie.substring(c_start, c_end))
}
}
return ""
}
</script>
</head>
<body>
<input type="text" id="userid"/><br />
<input type="password" id="password"/><br />
<input type="button" id="login" value="login" />
</body>
</html>
登陆动作,肯定要结合session,这就不是这个版讨论的了。