zoukankan      html  css  js  c++  java
  • Web项目,要求:保存用户名和密码在Cookie中,下次登录不再重新输入

    设计一个实现登录功能的Web项目,要求:保存用户名和密码在Cookie中,下次登录不再重新输入

    var cookie = {};
    //设置
    cookie.SetCookies=function(name,value,exptime){
    try{
    if(arguments.length == 2) return arguments.callee(name,value,30*24*60*60*1000);

    var exp = new Date();
    exp.setTime(exp.getTime() + exptime);
    document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString();
    }
    catch(e){
    throw new Error("SetCookies: " + e.message);
    return false;
    }
    }
    //获取

    cookie.GetCookies=function(name){
    try{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != null)
    return unescape(arr[2]);
    return null;
    }
    catch(e){
    throw new Error("GetCookies: " + e.message);
    return false;
    }
    }

    //提交时函数头省略获取
    var username = document.getElementById('username').value;
    var password = document.getElementById('password').value;
    cookie.SetCookies ("username",username);
    cookie.SetCookies ("password",password);

    //进入本页时 jquery 加载onload 别忘了导包
    $(document).ready(function(){
    //可以判断下null值。
    document.getElementById('username').value = cookie.GetCookies("username");
    document.getElementById('password').value = cookie.GetCookies("password");
    });
  • 相关阅读:
    linux 安装软件的方式
    git 基本操作
    交叉编译
    windows下 打印机打印操作类 VS2015
    VS2015 下 unicode 字符转换类
    C++ 多线程日志类的使用
    编译模板实例化
    C++中如何使用switch字符串
    linux下静态库与动态库
    jsoncpp 解码编码 中文为空 乱码问题
  • 原文地址:https://www.cnblogs.com/ydfq-home/p/5017351.html
Copyright © 2011-2022 走看看