cookie基础

// 设置
    function setCoolie(name, value, iDay) {

      var oData = new Date()

      oData.setDate(oData.getData() + iDay)

      document.cookie = name + '=' + value + ";expires" + oData 

    }
// 获取
 function getCookie(name) {

      var arr = document.cookie.split('; ')
      var i = 0

      for (i = 0; i < arr.length; i++) {
        var arr2 = arr[i].split('=')
        if (arr2[0] == name) {

          return arr2[1]

        }

      }
      return ""
    }

你可能感兴趣的:(cookie基础)