JQuery $.cookie 應用

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   sp   on   div   log   

 1 if($.cookie(‘username‘)){ 2       alert(‘cookie exists‘); 3       str = $.cookie(‘username‘); 4       strs = str.split(‘&‘); 5       $("input[name=‘username‘]").val(strs[0]); 6       $("input[name=‘password‘]").val(strs[1]); 7 } 8  9  if($("#rememberme").is(":checked")){10         $.cookie(‘username‘,$("input[name=‘username‘]").val() + "&" + $("input[name=‘password‘]").val(),{path:"/",expires:7});11 }else{12         $.cookie(‘username‘, null, { path: ‘/‘,expires: -1 });13 }

 以上例子是用$.cookie來本地cookie,很久以前的外掛程式了,慢慢學習中,跟大家分享一下

參數設定:
expires: (Number | Date)     

有效期間,可以設定一個整數作為有效期間(單位:天),也可以設定一個日期對象作為Cookie的到期日期。如果指定日期為負數,那麼此cookie將被刪除;如果不設定或者設定為null,那麼此cookie將被當作Session Cookie處理,並且在瀏覽器關閉後刪除

path:  (String)          Cookie的路徑屬性,預設是建立該cookie的頁面路徑

domain: (String)     Cookie的網域名稱屬性,預設是建立該cookie的頁面網域名稱

secure: (Boolean)  如果設為true,那麼此cookie的傳輸會要求一個安全性通訊協定,例如HTTPS

//參數為引用,懶得寫。例子自己手寫。

 

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.