2009-6
9
Cookie操作是我们在Web开发中经常会用到的功能,以往我们一般是通过javascript实现的。下面这款jquery插件是专门用来进行cookie操作的,包括cookie的添加、清除、读取……
你可以在这款插件的主页下载到它:http://plugins.jquery.com/project/Cookie
这里是一个示例页面:在线示例
当在页面中引用了jquery文件及该插件文件后,可进行如下操作:
设置cookie
设置一个名称为blog,值为css9.net的cookie:
$.cookie("blog", "css9.net");
设置一个名称为blog,值为css9.net的cookie,同时设置过期时间(expires属性)为7天:
$.cookie("blog", "css9.net", { expires: 7 });
设置一个名称为blog,值为css9.net的cookie,设置过期时间(expires属性)为7天,同时设置cookie的path属性为”/admin”
$.cookie("blog", "css9.net", { path: '/admin', expires: 7 });
读取Cookie:
读取名称为blog的cookie值:
alert( $.cookie("blog") );
删除cookie:
$.cookie("example", null);
我简单看了下插件脚本的内容,实现是非常简单的。为了这样一个功能,要多引用一个文件,增加一个http连接数,感觉有些不值。其实可以把这个插件里面的功能方法提出来,合并到网站的js文件中,使用时方法是一样的。
延伸阅读:
- 保持新鲜感:网页每次加载不同样式的实现方法
- 强大的Jquery图表绘制插件 —— jqPlot
- 完美显示文件树的Jquery插件(支持Ajax及多种动态脚本)
- 实现页面不同位置间平滑滚动的两种解决方案
- 从输入网址到显示网页,这个过程究竟发生了什么?
- 使用jQuery及Bing API实现简易搜索引擎
- 功能强大易用的Web视频播放器——Flowplayer(使用方法及演示)
- jQuery Tools——不可错过的jQuery UI库(五)
版权声明:
本站内容受著作权法保护。个人网站、blog转载时请遵循 “署名-非商业用途-保持一致” 的创作共用协议;商业网站或媒体未授权不得复制本站内容。
友情提示:
如对本文有任何疑问,或在示例的使用中遇到问题,或有好的建议,欢迎在下面留言共同学习,有问必答。


[...] 提示: 如果你在网页使用了jquery,那么可以用我之前介绍的jQuery cookie操作插件实现cookie的读写操作,不必再定义代码中的setCookie和getCookie方法。 [...]
I totally love this article. I think you could write some other things to make your blog more complete.For example: ed hardy.vibram five fingers.p90x workout schedule. mbt shoes. hardy caps. vibram fivefingers kso trek. mbt chapa dawn shoes.
ghd straightener
ugg ugg boots
replica louis vuitton handbags
edhardyI thought that many people can like.
i believe you are a good writer, but have you erver thought to write some special artcals for peopel who likes shopping very much. for exaple, the artical aboutlouis vuitton handbags orvibram fivefingers,ghd orchristian louboutin,ugg bootsand
swiss watches as well asmichael jordan shoeschi hair straightener,nfl football apparel,
t shirts. i think more and more people would comr to read your blogs.