JS cookie中文乱码解决方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

JS cookie中文乱码解决方法

  2020-05-13 我要评论

复制代码 代码如下:

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 用这个转换一下

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们