您现在的位置是:网站首页>文章详情文章详情
js获取指定键值的cookie
inlike2019-11-23【 原创文章 】 浏览(1764) 评论(0) 喜欢(31)
简介通过遍历方式获取指定名称的cookie值需要JQuery库支持
//获取cookie函数
function getCookie(name) {
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]);
// Does this cookie string begin with the name we want?l
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
标签
下一篇:SMAP与SMTP协议
相关文章
本栏推荐
标签云
猜你喜欢
站点信息
- 建站时间:2019-5-24
- 网站程序:like in love
- 主题模板:《今夕何夕》
- 文章统计:104条
- 文章评论:***条
- 微信公众号:扫描二维码,关注我们