DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> js存、取、刪除cookies實例
js存、取、刪除cookies實例
編輯:關於JavaScript     


<script>
//
//寫cookies函數 作者:翟振凱
function SetCookie(name,value)//兩個參數,一個是cookie的名子,一個是值
{
var Days = 30; //此 cookie 將被保存 30 天
var exp = new Date(); //new Date(&ldquo;December 31, 9998&Prime;);
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + &ldquo;=&rdquo;+ escape (value) + &ldquo;;expires=&rdquo; + exp.toGMTString();
}
function getCookie(name)//取cookies函數 http://
{
var arr = document.cookie.match(new RegExp(&ldquo;(^| )&rdquo;+name+&rdquo;=([^;]*)(;|$)&rdquo;));
if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)//刪除cookie
{
var exp = new Date();
exp.setTime(exp.getTime() &ndash; 1);
var cval=getCookie(name);
if(cval!=null) document.cookie= name + &ldquo;=&rdquo;+cval+&rdquo;;expires=&rdquo;+exp.toGMTString();
}

SetCookie (&ldquo;xiaoqi&rdquo;, &ldquo;3&Prime;)
alert(getCookie(&lsquo;xiaoqi&rsquo;));
</script>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved