Home > Web Front-end > JS Tutorial > body text

JS cookie Chinese garbled solution_javascript skills

WBOY
Release: 2016-05-16 17:01:54
Original
1112 people have browsed it

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
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!