Html中使用Cookie取值赋值

//设置Cookie
function setCookie(name, value) {
    var Days = 1;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path:/";
}
/*
 获取Cookie中的值
 */
function getCookie(objName) {//获取指定名称的cookie的值
    var arrStr = document.cookie.split("; ");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] == objName) {
            return decodeURI(temp[1]);
        }
    }
}

需要引用jquery.cookie.js

posted @ 2019-12-23 20:00  噜啦啦0001  阅读(4496)  评论(0编辑  收藏  举报