<script>
<P>//設定cookie 方法一<BR>function setCookie(name,value){ <BR> var exp = new Date(); <BR> exp.setTime(exp.getTime() 1*6060*110* );//有效期限1小時<BR> document.cookie = name "=" escape (value) ";expires=" exp.toGMTString(); <BR>}
<P>/*訪問cookie時一般要對容易注入的字符進行編碼,相應的在獲取cookie時要解碼,編碼方式有很多種,有時間的話寫一篇關於編碼解碼的博客*/
<P>//設定cookie 方法 二 直接儲存cookie<BR>document.cookie = "homepage = http://www.jb51.net";
<P> /*--------------------------------------------- -------------------------------------------------- --------*/
<P>//取cookies函數 方法 一<BR>function getCookie(name){
<P> var arr = document.cookie.match(new RegExp("(^| )" name "=([^;]*)(;|$)"));
<P> if(arr != null)
<P> return unescape(arr[2]);
<P> return null;
<P>}
<P>//取cookies函數 方法二<BR>function getCookie(key){<BR> if(key==null)<BR> return null;<a>》.(protoString. =='[object String]'|| Object.prototype.toString.call(key)=='[object Number]')<BR> {<BR> var arrStr = document.cookie.split(";"); <BR> for(var i= 0;i<arrStr.length;i ){<BR> var temp = arrStr[i].split("=");<BR> <BR> return unescape(temp[1]);<BR> return unescape(temp[1]);<BR> }<BR> return〜>*<BR> return㜀]l<af};
<BR></script>
在學習的時候很多js的方法遇到不會的就在網上找資料,直到掌握為止。