js页面传值,cookie

// 获取页面穿值
function GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null)
return decodeURI(r[2]);
return null;
}
// 获取cookie
function getcookie(name){
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
   return (arr=document.cookie.match(reg))?unescape(arr[2]):null;
}
//设置cookie
function addcookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}

posted @ 2019-02-26 09:01  Tane  阅读(1295)  评论(0编辑  收藏  举报