为了账号安全,请及时绑定邮箱和手机立即绑定

请问jQuery.cookie is not a function?

请问jQuery.cookie is not a function?

BIG阳 2019-06-19 19:15:39
jQuery.cookie is not a function
查看完整描述

4 回答

?
蛊毒传说

TA贡献1895条经验 获得超3个赞

jQuery.cookie = function(name, value, options) {

if (typeof value != 'undefined') {
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString();
}
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
}
$.cookie(name, value, {expires, path, domain, secure}); // 创建COOKIE
$.cookie(name); // 获取COOKIE



查看完整回答
反对 回复 2019-06-29
?
慕娘9325324

TA贡献1783条经验 获得超4个赞

var date=new Date();
date.setTime(date.getTime()+30*60*1000); //设置date为当前时间+30分
document.cookie="key=value; expires="+date.toGMTString(); //将date赋值给expires

查看完整回答
反对 回复 2019-06-29
  • 4 回答
  • 0 关注
  • 659 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信