欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript學(xué)習(xí)筆記之Cookie對象

 更新時間:2015年01月22日 11:21:28   投稿:hebedich  
本文主要簡單介紹了javascript中cookie對象的概念,以及cookie的讀取,寫入,刪除操作的方法,并附上示例,非常不錯,這里推薦給小伙伴們。

JavaScript Cookie

  Cookie對象:

  Cookie是一種以文件的形式保存在客戶端硬盤的Cookies文件夾中的用戶數(shù)據(jù)信息(Cookie數(shù)據(jù))。

  Cookie文件由所訪問的Web站點建立,以長久的保存客戶端與Web站點間的會話數(shù)據(jù),并且該Cookie數(shù)據(jù)只允許被所訪問的Web站點進行讀取。

  Cookie文件的格式:

  NS:Cookie.txt

  IE:用戶名@域名.txt

  有兩種類型的cookie:

  (1)持久性cookie,會被存儲到客戶端的硬盤上。

  (2)會話Cookie:不會存儲到客戶端的硬盤上,而是放在瀏覽器進程所處的內(nèi)存當(dāng)中,當(dāng)瀏覽器關(guān)閉則該會話cookie就銷毀了。

用JS實現(xiàn)Cookie操作

  寫入Cookie:

  document.cookie = " 關(guān)鍵字 = 值 [ ; expires = 有效日期 ] [;...]"

  讀取Cookie:

  document.cookie

  刪除Cookie:

  document.cookie = " 關(guān)鍵字 = ; expires = 當(dāng)前日期"

  備注:

  1.有效日期格式:Wdy,DD-Mon-YY HH:MM:SS GMT

  2.Wdy / Mon:英文星期 / 月份;

  3.還包含path、domain、secure屬性;

  4.每個Web站點(domain)可建立20個Cookie數(shù)據(jù);

  5.每個瀏覽器可存儲300個Cookie數(shù)據(jù),4k字節(jié);

  6.客戶有權(quán)禁止Cookie數(shù)據(jù)的寫入。

實例

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
  <head>
    <title>cookieTest.html</title>
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
  </head>
  <body>
    <script type="text/javascript">
        var today = new Date();
        var expiredDay = new Date();
        var msPerMonth = 1000 * 60 * 60 * 24 * 30;
        expiredDay.setTime(today.getTime() + msPerMonth); //一個月之后過期
        //寫入cookie
        document.cookie = "name=mengdd;expires="+expiredDay.toGMTString();
        document.writeln("cookie已經(jīng)寫到硬盤上了");
        //讀取cookie
        document.writeln("內(nèi)容是:" + document.cookie);
        document.writeln("expire day: " + expiredDay.toGMTString());
    </script>
  </body>
</html>

以上就是javascript中cookie對象的全部內(nèi)容了,希望大家能夠喜歡。

相關(guān)文章

最新評論