最新下载
热门教程
- 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记录是否第一次访问界面:
相关文章
- “洗代码即服务!”火了!“开源代码洗白”奇葩网上线 03-18
- “龙虾”突放大招!第一批“养龙虾”的极客实测 03-18
- 龙虾openclaw官网入口怎么进-2026最新下载链接与访问方法 03-18
- 哔哩哔哩网页版快捷入口-哔哩哔哩bilibili官网一键直达 03-18
- 在哪看漫窝 03-18
- jm天堂网页版官方登录入口-jm天堂网页版官网直接登录 03-18