js调用cookie实例总结

//删除cookie
    function delCookie(name){
    	var days = 7;
    	var value ="";
    	var path = "/";
    	var expires = new Date();
    	expires.setTime(expires.getTime() + days * 3600000 * 24);
    	//path = path == "" ? "" : ";path=" + path;
    	var _expires = (typeof days) == "string" ? "" : ";expires="
    			+ expires.toUTCString();
    	//var domain = ".banksteel.com";
    	//domain = domain == "" ? "" : ";domain=" + domain;
    	//document.cookie = name + "=" + value + _expires + path + domain;
    	document.cookie = name + "=" + value + _expires;
    }
  
   
    
 // 重写cookie内容(cookie名,cookie内容)
    function reWriteCookie(name ,value) {
    	var days = 7;
    	var path = "/";
    	var expires = new Date();
    	expires.setTime(expires.getTime() + days * 3600000 * 24);
    	//path = path == "" ? "" : ";path=" + path;
    	//var domain = ".banksteel.com";
    	//domain = domain == "" ? "" : ";domain=" + domain;
    	var _expires = (typeof days) == "string" ? "" : ";expires="
    			+ expires.toUTCString();
    	//document.cookie = name + "=" + value + _expires + path + domain;
    	document.cookie = name + "=" + value + _expires;
    }

 
    /*
     *根据cookie的name获取对应值
     */
    function getCookie(name) {
    	var cookieValue = "";
    	var search = name + "=";
    	if (document.cookie.length > 0) {
    		offset = document.cookie.indexOf(search);
    		if (offset != -1) {
    			offset += search.length;
    			end = document.cookie.indexOf(";", offset);
    			if (end == -1)
    				end = document.cookie.length;
    			cookieValue = unescape(document.cookie.substring(offset, end))
    		}
    	}
    	return cookieValue;
    }

  

转载于:https://www.cnblogs.com/guilf/p/9329064.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值