直接参考网易的函数

1
2
3
4
5
6
7
8
9
10
11
12
function getCookie(name) {
   var search = name + "="
   if(document.cookie.length > 0) {
      offset = document.cookie.indexOf(search)
      if(offset != -1) {
         offset += search.length
         end = document.cookie.indexOf(";", offset)
         if(end == -1) end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      }
      else return ""
   }

后计,直接使用jquery的cookie插件更方便,取一个cookie(name)赋值给foo

1
var foo= $.cookie('name');

发表评论