13
回答
关于JQUERY插件cookies
注册华为云得mate10,2.9折抢先购!>>>   

怎么浏览器关了就消失了?神奇死了啊,怎么会这样的呢

有效期怎么设置的?

举报
showrock
发帖于8年前 13回/2K+阅
共有13个答案 最后回答: 6年前

FF也是一样的情况,只要关掉浏览器再开,cookie就是空的

这个例子里也没有关于时间的设置啊,。。。。

//set 
$.cookies.set( 'sessid', 'dh3tr62fghe' ); //A cookie by the name 'sessid' now exists with the value 'dh3tr62fghe' 
 
//get 
var sessid = $.cookies.get( 'sessid' ); //Variable 'sessid' now holds the value 'dh3tr62fghe' 
 
//delete 
$.cookies.del( 'sessid' ); //The cookie named 'sessid' has been deleted. 
 
//test 
if( $.cookies.test() ) 
{ 
  //browser is accepting cookies 
} 
 
 
//JSON 
var jimData = {id: 1, name: 'jim'}; 
$.cookies.set( 'userdata', jimData ); //A cookie by the name 'userdata' now exists with a serialized copy of jimData 
 
var userData = $.cookies.get( 'userdata' ); //A variable named 'userData' now holds the unserialized object--should be identical to the variable 'jimData' 
 
 
//jQuery Extensions 
$( 'input.store' ).cookify(); //Inputs with class of 'store' are written to a cookie named after the input 
 
$( 'input.store' ).cookieFill(); //Inputs with class of 'store' are filled with the value of cookies with matching names 
 
$( 'input.store' ).cookieBind(); //Inputs with class of 'store' are filled with the value of cookies with matching names and whenever they change the cookie will be updated

var newOptions = {
domain: '*.mydomain.com',
path: '/somedir',
expiresAt: new Date( 2011, 1, 1 ),
secure: true
}
jaaulde.utils.cookies.set('myCookie', 'myValue', newOptions);

引用来自#8楼“showrock”的帖子

谢谢楼上~

请问本地是localhost

domain应该如何设置?

像你这种情况,可以不设置 domain

顶部