1.操作cookie的插件jquery.cookie.js
添加
$.cookie('the_cookie', 'the_value');
设置时长
$.cookie('the_cookie', 'the_value', { expires: 7 });
设置路径
$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });
读取
$.cookie('the_cookie'); // cookie存在 => 'the_value'
$.cookie('not_existing'); // cookie不存在 => null
删除
$.cookie('the_cookie', null);
3.将cookie写入文件
var COOKIE_NAME = 'username';
if( $.cookie(COOKIE_NAME) ){
$("#username").val( $.cookie(COOKIE_NAME) );
}
$("#check").click(function(){
if(this.checked){
$.cookie(COOKIE_NAME, $("#username").val() , { path: '/', expires: 10, domain: 'jquery.com', secure: true });
//var date = new Date();
//date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000)); //三天后的这个时候过期
//$.cookie(COOKIE_NAME, $("#username").val
前端实用的插件大全
最新推荐文章于 2025-05-26 09:00:00 发布