JS cookie 設定 查看 刪除

來源:互聯網
上載者:User

標籤:height   pre   需要   img   order   ==   div   重複   多少   

JScookie 常用的3個預設函數(庫)

<!DOCTYPE HTML><html><head><meta charset="utf-8"><title>無標題文檔</title><script>function setCookie(name, value, iDay)  //iday是多少天后到期{    var oDate=new Date();    oDate.setDate(oDate.getDate()+iDay);        document.cookie=name+‘=‘+value+‘;expires=‘+oDate;}  //黃色的等號其實是添加不是賦值的意思. 重複添加不會覆蓋//設定需要有到期的概念, 不設定會即時到期.function getCookie(name){    var arr=document.cookie.split(‘; ‘);        for(var i=0;i<arr.length;i++)    {        var arr2=arr[i].split(‘=‘); 
//cookie的儲存形式是  user= zhangsan, =是:的意思,split‘=‘ 切割cookie完成尋找功能                if(arr2[0]==name)        {            return arr2[1];        }    }        return ‘‘;}function removeCookie(name){    setCookie(name, 1, -1); //設定到期為-1天, 就是刪除了cookies, 實際上0也可以.}removeCookie(‘password‘);alert(document.cookie);</script></head><body></body></html>

 

記住使用者名稱

 

JS 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.