首页 > 语言 > JavaScript > 正文

JS cookie中文乱码解决方法

2024-05-06 16:00:12
字体:
来源:转载
供稿:网友
本篇文章主要是对JS中的cookie中文乱码解决方法进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助

复制代码 代码如下:


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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选