Home >Web Front-end >JS Tutorial >JS cookie Chinese garbled solution_javascript skills

JS cookie Chinese garbled solution_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:01:541157browse

Copy code The code is as follows:

function SetCookie(name, value) {
      var exp = new Date();
exp.setTime(exp.getTime() 3 * 24 * 60 * 60 * 1000); //Expires in 3 days
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;
    };


Copy code The code is as follows:

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

decodeURIComponent Use this to convert it
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn