<!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. iOS_SourceTree忽略CocoaPods文件

    原文作者:iOS_MingXing 原文地址(CSDN):http://blog.csdn.net/ios_mingxing/article/details/51487344 (有更改) 忽略文件内容 ...

  2. 【GO】GO语言学习笔记四

    流程控制 1.条件语句 举个栗子: if x>5 { return 1; }else{ return 0; } 注意:  条件语句不需要使用括号将条件包含起来(); 无论语句体内有几条语句, ...

  3. 简述id,instancetype和__kindof的区别

    id: 好处:可以调用任何对象方法 坏处:不能进行编译检查 + (id)person; instancetype 好处:自动识别当前类的对象 坏处:不会提示返回的类型 + (instancetype) ...

  4. CSS 的overflowhidden 属性详细解释

    overflow:hidden这个CSS样式是大家常用到的CSS样式,但是大多数人对这个样式的理解仅仅局限于隐藏溢出,而对于清除浮动这个含义不是很了解.      一提到清除浮动,我们就会想到另外一个 ...

  5. [原创]WKWebview点击图片查看大图

    大家都知道,WKWebview是没有查看大图的属性或者方法的,所以只能通过js与之交互来实现这一功能,原理:通过js获取页面的图片,把它存放到数组,给图片添加点击事件,通过index显示大图就行了 其 ...

  6. Big String-POJ2887块状数组

    Time Limit: 1000MS Memory Limit: 131072K Description You are given a string and supposed to do some ...

  7. Eclipse中安装配置Tomcat

    Eclipse(4.4.x及以上)中安装配置Tomcat 以下配置说明全部针对免安装版本 基于tomcat的安装目录和运行目录是可以不同的,本文都会进行说明 首先简单介绍一下tomcat的目录结构,一 ...

  8. 译\Node.js应用的持续部署

    Node.js应用的持续部署 翻译前 翻译自:https://blog.risingstack.com/continuous-deployment-of-node-js-applications/ 正 ...

  9. Python notes

    1. range()函数的使用: a = range(n) # a = range(0,n) b = range(m,n) # b = range(m,n) alist = list(a) # ali ...

  10. c++程序判断系统是Linux还是Windows

    用C++来实现,本来想了很多,后来越写越烂,而且结果总是不尽人意,干脆这样子好了: int main() { int judge = system("cls"); ) cout & ...