Jquery 实现 “下次自动登录” 记住用户名密码效能
Jquery 实现 “下次自动登录” 记住用户名密码功能
Jquery将用户名密码存储到cookie中
需要导入jquery.js和jquery.cookie.js
<html> <head> <title>test cookie</title> <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script src="Scripts/jquery.cookie.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { if ($.cookie("rmbUser") == "true") { $("#ck_rmbUser").attr("checked", true); $("#txt_username").val($.cookie("username")); $("#txt_password").val($.cookie("password")); } }); //记住用户名密码 function Save() { if ($("#ck_rmbUser").attr("checked")) { var str_username = $("#txt_username").val(); var str_password = $("#txt_password").val(); $.cookie("rmbUser", "true", { expires: 7 }); //存储一个带7天期限的cookie $.cookie("username", str_username, { expires: 7 }); $.cookie("password", str_password, { expires: 7 }); } else { $.cookie("rmbUser", "false", { expire: -1 }); $.cookie("username", "", { expires: -1 }); $.cookie("password", "", { expires: -1 }); } }; </script> </head> <body> <div> 用户名:<input type="text" id="txt_username"/><br /> 密码:<input type="text" id="txt_password"/><br /> <input type="checkbox" id="ck_rmbUser"/>记住用户名和密码<br /> <input type="submit" id="sub" value="登录" onclick="Save()"/> </div> </body> </html>
相关推荐
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17