jquery.cookie.js 790 B

1234567891011121314151617181920212223242526
  1. // 设置cookie
  2. function setCookie(c_name, value, expiredays) {
  3. var exdate = new Date();
  4. exdate.setDate(exdate.getDate() + expiredays);
  5. document.cookie = c_name + "=" + escape(value) + ";expires = " + exdate.toGMTString() + ";path = /";
  6. }
  7. // 读取cookie
  8. function getCookie(c_name) {
  9. if (document.cookie.length > 0) {
  10. c_start = document.cookie.indexOf(c_name + "=")
  11. if (c_start != -1) {
  12. c_start = c_start + c_name.length + 1
  13. c_end = document.cookie.indexOf(";", c_start)
  14. if (c_end == -1)
  15. c_end = document.cookie.length
  16. return unescape(document.cookie.substring(c_start, c_end))
  17. }
  18. }
  19. return ""
  20. }
  21. // 清除cookie
  22. function clearCookie(name) {
  23. setCookie(name, "", -1);
  24. }