最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
JQUERY.COOKIE插件的基本用法
时间:2022-06-25 17:37:56 编辑:袖梨 来源:一聚教程网
jQuery.cookie的基本用法:
Include script after the jQuery library (unless you are packaging scripts somehow else):
Create session cookie:
$.cookie('name', 'value');
Create expiring cookie, 7 days from then:
$.cookie('name', 'value', { expires: 7 });
Create expiring cookie, valid across entire site:
$.cookie('name', 'value', { expires: 7, path: '/' });
Read cookie:
$.cookie('name'); // => "value"
$.cookie('nothing'); // => undefined
Read all available cookies:
$.cookie(); // => { "name": "value" }
Delete cookie:
// Returns true when cookie was successfully deleted, otherwise false
$.removeCookie('name'); // => true
$.removeCookie('nothing'); // => false
// Need to use the same attributes (path, domain) as what the cookie was written with
$.cookie('name', 'value', { path: '/' });
// This won't work!
$.removeCookie('name'); // => false
// This will work!
$.removeCookie('name', { path: '/' }); // => true
JQUERY的COOKIE实例
jquery的cookie插件可以方便操作cookie,首先引入jquery.cookie.js文件,可以去官网下载。
以下使用jquery的cookie实现一个简单的功能,一个公共栏,可以点击展开或者收缩,第一次进入页面默认展开,第二次以后进入页面默认收缩,但是点击也可以展开。
通过jquery的cookie记录是否第一次访问界面:
相关文章
- 洛克王国世界帽兜娃娃技能怎么搭配 09-16
- 二重螺旋螺旋上天技能如何触发 09-16
- 地下城堡4骑士与破碎编年史巨角怎么打 09-16
- 三国望神州鲍信如何获取 09-16
- 光遇旋转舞者复刻活动怎么玩 09-16
- 原神现在是我的了成就怎么做-现在是我的了成就达成攻略 09-16