1、创建Cookie
$.cookie("example", "foo"); //创建名为“example”的cookie
2、设置cookie的有效期
$.cookie("example", "foo",{ expires: 7 }); //保存7天
3、设置cookie的有效期一个小时
var expires= new Date(); var expiresDate = new Date(); expiresDate.setTime(expires.getTime() + (60* 60 * 1000)); $.cookie('example','foo',{ expires: expiresDate, path: '/' });
4、设置cookie的保存路径
$.cookie('example','foo',{ expires: expiresDate, path: '/' }); //保存到根目录
$.cookie('example','foo',{ expires: expiresDate, path: '/admin' });//保存到admin目录
5、删除cookie
$.cookie("example", null); //如果设置为空字符串,不能删除cookie,只是将cookie的值设置为空字符串