javascript 取得get参数, set/get cookie

* javascript 取得get参数

var qs = function(name) {
	var ps = location.search.substr(1).split('&').find(function(s) {
		return s.split('=')[0] === name;
	});
	if (ps) { return decodeURIComponent(ps.substr(name.length+1)); }
	return undefined;
};

* javascript set/get cookie

if (typeof et === "undefined") {
	var et = {};
}
et.other = et.other || {};
et.other.getcookie = function(name) {
	var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
	if (arr = document.cookie.match(reg)) {
		return decodeURIComponent(arr[2]);
	}
	return undefined;
};
et.other.setcookie = function(c_name,value,expiredays) {
	expiredays = expiredays || 7;
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name+ "="  + decodeURIComponent(value) +
			((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
};
// et.other.setcookie("NOPROMPTINSEVENDAY", undefined, -1);

猜你喜欢

转载自blog.csdn.net/fareast_mzh/article/details/84334649