日期:2014-05-16 浏览次数:20323 次
<Script> var today = new Date(); var expireDay = new Date(); var msPerMonth = 24*60*60*1000*31; expireDay.setTime( today.getTime() + msPerMonth ); document.cookie = "name=Hubert;expires=" + expireDay.toGMTString(); document.write("已经将 Cookie 写入你的硬盘中了!<br>"); document.write("内容是:", document.cookie, "<br>"); document.write("这个 Cookie 的有效时间是:"); document.write(expireDay.toGMTString()); </Script>
<Script> var today = new Date(); var expireDay = new Date(); var msPerMonth = 24*60*60*1000*31; expireDay.setTime( today.getTime() + msPerMonth ); function setCookie(Key,value) { document.cookie = Key + "=" + value + ";expires=" + expireDay.toGMTString(); } setCookie("NAME","HUBERT"); document.write("累计的 Cookies 如下:<BR>"); document.write(document.cookie); </Script>
<Script> function getCookie(Key){ var search = Key + "="; begin = document.cookie.indexOf(search); if (begin != -1) { begin += search.length; end = document.cookie.indexOf(";",begin); if (end == -1) end = document.cookie.length; return document.cookie.substring(begin,end); } } document.write("嗨! ",getCookie("name"), " 欢迎光临..") </Script>
<Script> var today = new Date(); function delCookie(Key) { document.cookie = Key + "=;expires=today.toGMTString"; } document.write("现有的 Cookies 如下:<BR>"); document.write(document.cookie, "<BR>"); delCookie("name"); document.write("删除后的 Cookies 如下:<BR>"); document.write(document.cookie); </Script>