<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>记住用户名密码操作</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="http://apps.bdimg.com/libs/jquery.cookie/1.4.1/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<ul>
<li>
<input type="text" id="username" name="username" class="form-control" placeholder="用户名" autofocus/>
</li>
<li>
<input type="password" id="userpwd" name="userpwd" class="form-control" placeholder="密码" autofocus/>
</li>
<li>
<input type="checkbox" name="rememberUser" checked="true" id="rememberUser" />记住密码
</li>
<li>
<input type="submit" class="btn" value="设置" οnclick="saveUserInfo()" />
</li>
</ul>
<script type="text/javascript">
/*记住用户名和密码*/
$(function() {
if($.cookie("rememberUser")) {
$("#rememberUser").attr("checked", true);
$("#username").val($.cookie("userName"));
$("#userpwd").val($.cookie("passWord"));
}
});
//如果$.cookie("rememberUser")为true,即把cookie里存的userName,passWord的值赋给id是username,userpwd的input;
function saveUserInfo() {
if($("#rememberUser").prop("checked") == true) {
var userName = $("#username").val();
var passWord = $("#userpwd").val();
$.cookie("rememberUser", "true", {
expires: 7
}); // 存储一个带7天期限的 cookie
$.cookie("userName", userName, {
expires: 7
}); // 存储一个带7天期限的 cookie
$.cookie("passWord", passWord, {
expires: 7
}); // 存储一个带7天期限的 cookie
} else {
$.cookie("rememberUser", "false", {
expires: -1
}); // 删除 cookie
$.cookie("userName", '', {
expires: -1
});
$.cookie("passWord", '', {
expires: -1
});
}
}
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>记住用户名密码操作</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="http://apps.bdimg.com/libs/jquery.cookie/1.4.1/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<ul>
<li>
<input type="text" id="username" name="username" class="form-control" placeholder="用户名" autofocus/>
</li>
<li>
<input type="password" id="userpwd" name="userpwd" class="form-control" placeholder="密码" autofocus/>
</li>
<li>
<input type="checkbox" name="rememberUser" checked="true" id="rememberUser" />记住密码
</li>
<li>
<input type="submit" class="btn" value="设置" οnclick="saveUserInfo()" />
</li>
</ul>
<script type="text/javascript">
/*记住用户名和密码*/
$(function() {
if($.cookie("rememberUser")) {
$("#rememberUser").attr("checked", true);
$("#username").val($.cookie("userName"));
$("#userpwd").val($.cookie("passWord"));
}
});
//如果$.cookie("rememberUser")为true,即把cookie里存的userName,passWord的值赋给id是username,userpwd的input;
function saveUserInfo() {
if($("#rememberUser").prop("checked") == true) {
var userName = $("#username").val();
var passWord = $("#userpwd").val();
$.cookie("rememberUser", "true", {
expires: 7
}); // 存储一个带7天期限的 cookie
$.cookie("userName", userName, {
expires: 7
}); // 存储一个带7天期限的 cookie
$.cookie("passWord", passWord, {
expires: 7
}); // 存储一个带7天期限的 cookie
} else {
$.cookie("rememberUser", "false", {
expires: -1
}); // 删除 cookie
$.cookie("userName", '', {
expires: -1
});
$.cookie("passWord", '', {
expires: -1
});
}
}
</script>
</body>
</html>