设置cookie 函数直接上代码:
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; }
设置cookie:
setCookie("key", ‘value‘, 1);
cookie检测:
document.cookie.indexOf("key")
返回值 -1表示不存在此cookie
时间: 2024-10-07 06:07:04