jQuery操作cookie

來源:互聯網
上載者:User

標籤:style   blog   color   sp   strong   檔案   div   on   log   

  驗證jquery的cookie外掛程式時才知道原先檔案一直在案頭上放著執行發現沒有效果,檔案必須放在web伺服器下面執行才會生效,暈菜!

$.cookie(name,value,{expires: 7,path:‘/‘,domin:‘jquery.com‘,secure:true})
參數詳解:
     expires: 7,//有限日期,可以是整數或一個日期(單位:天) 如果省略,那麼建立的cookie是會話cookie,將在使用者退出瀏覽器時被刪除。    path:‘/‘,//cookie被儲存的路徑 預設與建立頁路徑一致   domin:‘jquery.com‘,//cookie網域名稱屬性 預設值域建立頁路徑一致   secure:true//一個布爾值 表示傳輸cookie時 知否需要一個安全性通訊協定

1.讀取cookie

   $.cookie(‘the_cookie‘); // 獲得cookie值

2.設定cookie

  $.cookie(‘the_cookie‘, ‘the_value‘); // 設定cookie

3.設定帶有效期間的cookie值

   $.cookie(‘the_cookie‘, ‘the_value‘, { expires: 7 }); //設定帶時間的cookie 儲存時間7天

4.刪除cookie  

  $.cookie(‘the_cookie‘, ‘‘, { expires: -1 }); // 刪除
  $.cookie(‘the_cookie‘, null); // 刪除 cookie

5.建立一個cookie 包括有效期間 路徑 網域名稱等

  $.cookie(‘the_cookie‘, ‘the_value‘, {expires: 7, path: ‘/‘, domain: ‘jquery.com‘, secure: true});

刪除cookie注意事項:

  @1.$.cookie(name,null)  在銷毀cookie時,其可選項參數中的路徑和網域名稱必須與設定時一樣 否則不能被銷毀

 

jQuery操作cookie

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.