<div id="link"></div> <script> function SetCookie(cookieName, cookieValue, path, domain, secure){ var expires = new Date(); expires.setTime(expires.getTime() + 9000000000); document.cookie = escape(cookieName) + '=' + escape(cookieValue) + (expires ? '; expires=' + expires.toGMTString() : '') + (path ? '; path=' + path : '/') + (domain ? '; domain=' + domain : '') + (secure ? '; secure' : ''); } function GetCookie(name){ var cookie_start = document.cookie.indexOf(name); var cookie_end = document.cookie.indexOf(";", cookie_start); return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length))); } function DelCookie(cookieName, cookieValue, path, domain, secure){ var cookieValue="hello"; var expires = new Date(); expires.setTime(expires.getTime() - 100000); document.cookie = escape(cookieName) + '=' + escape(cookieValue) + (expires ? '; expires=' + expires.toGMTString() : '') + (path ? '; path=' + path : '/') + (domain ? '; domain=' + domain : '') + (secure ? '; secure' : ''); } //创建,或是修改cookie SetCookie("name","123"); SetCookie("site","fsdf"); //读取cookie GetCookie("name"); //作为超级链接 document.getElementById("link").innerHTML="http://xxx.com/?name="+GetCookie("name"); </script> 提问者评价
参考至: http://zhidao.baidu.com/link?url=fRS5Pa05JGP2LgKwVkcLtYyvQxRoSx9iq6LsyUbFkdlSIXR8VN3yHMCbyKO7CNSvYQEFDxpfszbm_n9G4XlRh_