JavaScript操作cookie
當(dāng)前位置:點晴教程→知識管理交流
→『 技術(shù)文檔交流 』
寫入和讀取Cookie是一種常見的功能,可惜JavaScript對此的直接支持并不算完善,下面是幾個操作Cookie的函數(shù),用起來還是蠻方便的。 // utility function to retrieve an expiration date in proper // format; pass three integer parameters for the number of days, hours, // and minutes from now you want the cookie to expire (or negative // values for a past date); all three parameters are required, // so use zeros where appropriate function getExpDate(days, hours, minutes) { } // utility function called by getCookie( ) function getCookieval_r(offset) { } // primary function to retrieve cookie by name function getCookie(name) { } // store cookie value with optional details as needed function setCookie(name, value, expires, path, domain, secure) { } // remove the cookie by setting ancient expiration date function deleteCookie(name,path,domain) { } 將上面的幾個js命名為cookie.js,下面演示其基本用法 <script type="text/javascript" src="cookie.js"></script> <script type="text/javascript"> </script> Chapter 1.9 example <br> <input type="text" id="name" size="20" /> <input type="button" value="setCookie" onclick="foo()" /> <div id="show"></div> 可以同時開兩個窗口看看,輸入框不輸入值,按按鈕相當(dāng)于察看當(dāng)前cookie。 該文章在 2010/9/2 10:11:07 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |