This article mainly introduces JS settings Cookie Related information about validity period detection cookies. Friends who need it can refer to
Setting cookies Function Directly upload the code:
function setCookie(name, value, days) { //设置cookie var d = new Date(); d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "expires=" + d.toUTCString(); document.cookie = name + "=" + value + "; " + expires; }
Set cookies:
setCookie("key", 'value', 1);
Cookie detection:
document.cookie.indexOf("key")
The return value -1 indicates that this cookie does not exist
The above is the detailed content of Detailed explanation of examples of JS detection. For more information, please follow other related articles on the PHP Chinese website!