现在的位置: 首页 > 综合 > 正文

JS读取cookie(记住账号密码)

2013年10月17日 ⁄ 综合 ⁄ 共 1060字 ⁄ 字号 评论关闭

很多登录功能上都有个“记住密码”的功能,其实无非就是对cookie的读取。

下面展示这个功能的代码,原作者已无法考究。。。。

测试方法:直接输入账号密码,提交后,刷新页面,再输入同样的账号,就可以显示

?
<!DOCTYPE
HTML>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8"
 />
<title>js
COOKIE 记住帐号或密码</
title>
<script type="text/javascript">
    window.onload=function
onLoginLoaded() {
        if
(isPostBack == "False") {
            GetLastUser();
        }
    }
     
    function
GetLastUser() {
        var
id = "49BAC005-7D5B-4231-8CEA-16939BEACD67";//GUID标识符
        var
usr = GetCookie(id);
        if
(usr != null) {
            document.getElementById('txtUserName').value
= usr;
        }
else {
            document.getElementById('txtUserName').value
= "001";
        }
        GetPwdAndChk();
    }
    //点击登录时触发客户端事件
     
    function
SetPwdAndChk() {
        //取用户名
        var
usr = document.getElementById('txtUserName').value;
        alert(usr);
        //将最后一个用户信息写入到Cookie
        SetLastUser(usr);
        //如果记住密码选项被选中
        if
(document.getElementById('chkRememberPwd').checked == true) {
            //取密码值
            var
pwd = document.getElementById('txtPassword').value;
            

抱歉!评论已关闭.