首页 >web前端 >js教程 >JS cookie中文乱码解决方法_javascript技巧

JS cookie中文乱码解决方法_javascript技巧

WBOY
WBOY原创
2016-05-16 17:01:541161浏览

复制代码 代码如下:

function SetCookie(name, value) {
        var exp = new Date();
        exp.setTime(exp.getTime() + 3 * 24 * 60 * 60 * 1000); //3天过期
        document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
        return true;
    };

    function getCookie(name) {
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null) return arr[2]; return null;
    };


复制代码 代码如下:

 var currentServiceAliasName = getCookie("appName");
        var displayName = "";
        if (currentServiceAliasName != null && currentServiceAliasName != "" && currentServiceAliasName != "undefined")
            displayName = decodeURIComponent(currentServiceAliasName) + " . " + counterName;
        else
        displayName = counterName;

decodeURIComponent 用这个转换一下
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn