设置和读取cookie的javascript代码 时间:2020-05-12 人气:0 <script language="javascript"> function setcookie(name, value) { //设置名称为name,值为value的cookie document.cookie = name + "=" + value document.location.reload(); } function setCookie() { document.cookie="a=abcd;" document.cookie="b=5678;" document.location.reload(); } var mycookie = document.cookie; function readcookie(name) { var start1 = mycookie.indexOf(name + "="); if (start1== -1) alert("cookies not found"); else { start=mycookie.indexOf("=",start1)+1; var end = mycookie.indexOf(";",start); if (end==-1) { end=mycookie.length;} var value=unescape(mycookie.substring(start,end)); if (value==null) {alert("No cookies found!");} else {alert("cookie变量:"+name+" 的值是 :"+value);} } } </script> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 加载全部内容