jquery简单实现记住密码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <%--<script type="text/javascript" src="jslib/jquery-1.8.3.min.js"></script> --%> <script type="text/javascript" src="jslib/jquery-1.9.1.min.js"></script> <script type="text/javascript" src="jslib/jquery.cookie.js"></script> <script type="text/javascript"> //初始化页面时验证是否记住了密码 $(document).ready(function() { alert("用户名:" + $.cookie("userName") + " 密码:" + $.cookie("passWord")); if ($.cookie("rmbUser") == "true") { $("#rmbUser").attr("checked", true); $("#user").val($.cookie("userName")); $("#pass").val($.cookie("passWord")); } }); //保存用户信息 function saveUserInfo() { if ($("#rmbUser").attr("checked") == "checked") { var userName = $("#user").val(); var passWord = $("#pass").val(); $.cookie("rmbUser", "true", { expires : 7 }); // 存储一个带7天期限的 cookie $.cookie("userName", userName, { expires : 7 }); // 存储一个带7天期限的 cookie $.cookie("passWord", passWord, { expires : 7 }); // 存储一个带7天期限的 cookie } else { $.cookie("rmbUser", "false", { expires : -1 }); $.cookie("userName", '', { expires : -1 }); $.cookie("passWord", '', { expires : -1 }); } } </script> </head> <body> <div> <form action="" method="post"> <table> <tr> <th>用户名:</th> <td><input type="text" id="user" /></td> </tr> <tr> <th>密码:</th> <td><input type="password" id="pass" /></td> </tr> <tr> <th>记住密码</th> <td><input type="checkbox" id="rmbUser" /><input type="submit" value="提交" onclick="saveUserInfo()" /></td> </tr> </table> </form> </div> </body> </html>
相关推荐
houmenghu 2020-11-17
kentrl 2020-11-10
逍遥友 2020-10-26
jincheng 2020-09-01
Blueberry 2020-08-15
xclxcl 2020-08-03
zmzmmf 2020-08-03
阳光之吻 2020-08-03
PkJY 2020-07-08
hzyuhz 2020-07-04
89407707 2020-06-27
服务器端攻城师 2020-06-26
阳光岛主 2020-06-25
笨重的蜗牛 2020-06-20
xuanwenchao 2020-06-14
Lophole 2020-06-13
明瞳 2020-06-12
songerxing 2020-06-11