复制代码 代码如下:
var cookieName = "cookie名字";
var cookieValue = null;//返回cookie的value值
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');//将获得的所有cookie切割成数组
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];//得到某下标的cookies数组
if (cookie.substring(0, cookieName.length + 2).trim() == cookieName.trim() + "=") {//如果存在该cookie的话就将cookie的值拿出来
cookieValue = cookie.substring(cookieName.length + 2, cookie.length);
break
}
}
}
if (cookieValue != "" && cookieValue != null) {//如果存在指定的cookie值
alert(cookieValue);
} else {<span style="font-family: Arial, Helvetica, sans-serif;">//如果cookie的值是空</span>
alert("not cookie!!!");
}
复制代码 代码如下:
//去除空格
String.prototype.trim = function () {
return this.replace(new RegExp("(^[\\s]*)|([\\s]*$)", "g"), "");
}
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!