<!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;
}

面向对象cookie增删查的更多相关文章

  1. 6.在MVC中使用泛型仓储模式和依赖注入实现增删查改

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...

  2. 2015.8.2 jdbc实现商品类的增删查改

    在惠普济宁基地进行了两周sql和java的学习,学到很多东西 刚才实现了用jdbc访问数据库对数据库进行操作,是用eclipse写的,过几天移植到NetBeans上,个人还是比较习惯看图形化界面 前几 ...

  3. IOS CoreData的(增删查改)

    (1).CoreDataa>什么是CoreDatab>CoreData增删改查 "什么时候使用COredata 什么时候使用FMDatabases"CoreData 在 ...

  4. 基于.net的分布式系统限流组件 C# DataGridView绑定List对象时,利用BindingList来实现增删查改 .net中ThreadPool与Task的认识总结 C# 排序技术研究与对比 基于.net的通用内存缓存模型组件 Scala学习笔记:重要语法特性

    基于.net的分布式系统限流组件   在互联网应用中,流量洪峰是常有的事情.在应对流量洪峰时,通用的处理模式一般有排队.限流,这样可以非常直接有效的保护系统,防止系统被打爆.另外,通过限流技术手段,可 ...

  5. 在MVC中使用泛型仓储模式和依赖注入实现增删查改

    标签: 原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository ...

  6. 学习记录——使用PHP实现数据增删查改等基本功能(前后端分离)

    萌新初次学习服务器端语言,分享学习经验 实现功能:1.显示数据表    2.对数据进行分页    3.对数据进行增删查改 由于本萌新采用前后端完全分离方案,所以数据传输用的ajax,为了提高代码的复用 ...

  7. 3.EF 6.0 Code-First实现增删查改

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-entity-framework-5-0-code- ...

  8. 4.在MVC中使用仓储模式进行增删查改

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-using-the-repository-pattern-in-mvc/ 系列目录: ...

  9. 5.在MVC中使用泛型仓储模式和工作单元来进行增删查改

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...

随机推荐

  1. mha安装使用手册

    mha安装使用手册 注:目前mha最新的版本代码已经不放到google code网站了,而是放在github上,最新的版本为0.57,github链接如下: mha manager:https://g ...

  2. python:字符串转换成字节的三种方式

    str='zifuchuang' 第一种 b'zifuchuang'第二种bytes('zifuchuang',encoding='utf-8')第三种('zifuchuang').encode('u ...

  3. three.js初涉略(一)

    <!-- 最近要研究一下webgl,发现了webgl中文网(http://www.hewebgl.com/article/articledir/1).边研究教程边做下记录 --> thre ...

  4. 关于php留言本网站的搭建

    1.检查php,http服务是否安装 [root@localhost ~]# rpm -qa | grep http httpd-tools--.el7.centos.x86_64 httpd--.e ...

  5. Milliard Vasya's Function-Ural1353动态规划

    Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning mathematician. He decided to make ...

  6. windows重建图标缓存(解决快捷方式图标丢失,图标加载时间长问题)

    新建一个文本文档,把下边的代码输入进去,保存为.bat格式,运行即可 有快捷方式图标丢失或者觉得图标加载速度慢了,就run一下这个,很实用的小工具 rem 关闭Windows外壳程序explorer ...

  7. jQuery validation学习(1)验证只输入空格通过验证

    当input输入了空格是不会提示信息的 一般会去除空格然后进行验证 这个时候就要添加onkeyup事件去除左侧的空格 验证只输入空格通过验证 //添加验证手机方法 jQuery.validator.a ...

  8. 第一、初识C语言

    1·C语言强大而灵活,如python,LISP,FORTRAN,Perl,Logo,BASIC,PASACAL的编译器和解释器都是C语言编写的. 2·C语言的指针错误往往难以察觉,但这恰好告诉我们,一 ...

  9. java 调用axis2 webservice

    import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; import org.apach ...

  10. 今天学的是 HTML基本元素、基本语法元素特点等,就发图片吧。

    现在我们新手用的软件是:Adobe Dreamweaver CS6 按照下面格式来改,以后点HTML5直接就改过来了. 可以敲敲这些代码,大家一起学习. <!doctype html>&l ...