设置cookie的方法

方法一:

set: function (name, value, days) {
var d = new Date;
d.setTime(d.getTime() + 24days);
window.document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString();
},


get: function (name) {
var v = window.document.cookie.match('(^|;) ?' + name + '=({FNXX==XXFN}*)(;|$)');
return v ? v[2] : null;
},


delete: function (name) {
this.set(name, '', -1);
}

方法二:

 function setCookie(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;
    }




    function getCookie(cname) {
       
 var name = cname + "=";
        var ca = document.cookie.split(';');
       
    for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }

你可能感兴趣的:(随记)