• 面向对象cookie增删查


    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    </head>
    <body>
    <input type="text" name="txt" id="txt" placeholder="用户名" />
    <input type="text" name="password" id="password" placeholder="密码" />
    <input type="button" name="reset" id="reset" value="重置" />
    <input type="button" name="get" id="get" value="获取" />
    </body>
    <script src="js/cookie.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
    function Cookie(){
    this.oTxt=document.getElementById("txt");
    this.oPd=document.getElementById("password");
    this.oReset=document.getElementById("reset");
    this.oGet=document.getElementById("get");
    }
    Cookie.prototype.setCookie=function(){
    this.oTxt.onblur=function(){
    this.setcookie('user',this.value,10);
    }
    this.oPd.onblur=function(){
    this.setcookie('pwd',this.value,10);
    }
    }
    Cookie.prototype.delCookie=function(){
    var This=this;
    this.oReset.onclick=function(){
    This.oTxt.delcookie('user');
    This.oPd.delcookie('pwd');
    This.oTxt.value='';
    This.oPd.value='';
    }
    }
    Cookie.prototype.getCookie=function(){
    var This=this;
    this.oGet.onclick=function(){
    alert(This.oTxt.getcookie('user'));
    alert(This.oPd.getcookie('pwd'));
    }
    }
    var cookie=new Cookie();
    cookie.setCookie();
    cookie.delCookie();
    cookie.getCookie();
    </script>
    </html>

    cookie.js

    Object.prototype.setcookie=function( name,val,day){
    this.oDate=new Date();//当前时间
    this.oDate.setDate(this.oDate.getDate()+day);//过期时间
    document.cookie=name+'='+val+';'+'expires='+this.oDate;
    }
    Object.prototype.delcookie=function( name ){
    this.setcookie(name,1,-1);//利用过期时间
    }
    Object.prototype.getcookie=function( name ){
    this.arr=document.cookie.split( '; ' );
    for( var i=0;i<this.arr.length;i++ ){
    this.arr1=this.arr[i].split('=');
    if( this.arr1[0]==name ){
    return this.arr1[1];
    }
    }
    return 0;
    }



  • 相关阅读:
    Python 描述符(descriptor) 杂记
    Celery 使用简介
    异步任务神器 Celery 简明笔记
    高性能框架gevent和gunicorn在web上的应用及性能测试
    Flask + Gunicorn + Nginx 部署
    Mysql查看最大连接数和修改最大连接数
    配置 influxDB 鉴权及 HTTP API 写数据的方法
    Java 字符串拼接 五种方法的性能比较分析 从执行100次到90万次
    linux端口开放指定端口的两种方法
    java自带的监控工具VisualVM一
  • 原文地址:https://www.cnblogs.com/sunny123-/p/5987136.html
Copyright © 2020-2023  润新知