转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> Web开发 >> 正文
JavaScript写的cookie类         ★★★★

JavaScript写的cookie类

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1492 更新时间:2009/4/23 11:26:59
nbsp;             this.init();
                  return false;
                 }
               var cookie=document.cookie;
               if(cookie.indexOf(this.key+"=")!=-1)
                 {if(!confirm("欲保存的cookie名称已经存在,是否要进行替换?"))
                                    {this.init();
                                         return false;
                                        }                    
                 }
               var dt=new Date();
               dt.setTime(dt.getTime()+this.expires);
                             document.cookie=this.key+"="+this.value+";expires="+dt.toGMTString();
                             this.init();
               return true;
              }
   this.get=function(key)//取得名为key的cookie的值
              {if(key==""||key.match(/[,; ]/))
                 {alert("请正确设置欲查找的cookie名称!")
                  return false;
                 }
               var cookie=document.cookie;
               var start=cookie.indexOf(key+"=");
               if(start==-1)
                 {alert("欲查找的cookie不存在!")
                  return false;
                 }
               var end=cookie.indexOf(";",start);
                             if(end==-1)
                               end=cookie.length;
               var getCookie=cookie.substring(start+key.length+1,end);
               alert("cookie:"+key+"的值为"+getCookie);
               return getCookie;
              }
   this.showAll=function(){alert("共有以下cookie对:\n"+document.cookie.split(";").toString().replace(/,/g,"\n"));}//显示所有cookie
   this.del=function(key)//删除名为key的cookie
              {if(key==""||key.match(/[,; ]/))
                 {alert("请正确设置欲删除的cookie名称!")
                  return false;
                 }
                             var dt=new Date();
               dt.setTime(dt.getTime());
                             document.cookie=key+"=eyunDelete;expires="+dt.toGMTString();
                             this.init();
               return true;
              }
   this.destroy=function()//销毁所有cookie
                    {var dt=new Date();
                   dt.setTime(dt.getTime());
                                     while(document.cookie!="")
                                       document.cookie=document.cookie+";expires="+dt.toGMTString();
                                     this.init();
                                     return true
                                    }
  }
var cookieTest=new eyunCookie()
function settest()
{cookieTest.key="test"
 cookieTest.value="ok"
 cookieTest.expires=31536000000
 cookieTest.set()
}
</script>
<input type=button onclick=cookieTest.showAll() value=read><input type=button onclick="cookieTest.set('a','test',31536000000)" value=setA><input type=button onclick="settest();" value=setTest><input type=button onclick="cookieTest.destroy()" value=clear><input type=button onclick=cookieTest.get("test") value=gettest><input type=button onclick=cookieTest.get("a") value=geta><input type=button onclick=cookieTest.set("test",1,31536000000) value=resetTest><input type=button onclick=cookieTest.del("test") value=delTest>

上一页  [1] [2] 


[Delphi程序]开发Web应用程序中Cookie使用的问题  [VB.NET程序]dvbbs 7.1.0 cookie 存在泄露绝对路径漏洞
[Web开发]javascript读写cookie的一个小demo  [Web开发]初学Javascript之cookie篇(译)
[Web开发]Asp.net中Cookie简明参考  [Web开发]ASP.NET状态存储管理九大兵器之五(Cookie)
[Web开发]用ASP.NET加密Cookie数据  [Web开发]ASP.NET Forms Authentication所生成Cookie的安全…
[Web开发][原创]VB.net技巧之七----asp.net中cookie的使用  [Web开发]ASP.NET中Cookie编程的基础知识(5)
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台