//保存cookie

function setCookie(name,value,iTime){

  var oDate = new Date();

  //设置cookie过期时间

  oDate.setDate(oDate.getDate()+iTime);

  document.cookie = name+'='+value+';expires='+oDate.toGMTString();

}

//获取cookie

function getCookie(name){

  //cookie中的数据都是以分号加空格区分开

  var arr = document.cookie.split("; ");

  for(var i=0; i<arr.length; i++){

    if(arr[i].split("=")[0] == name){

      return arr[i].split("=")[1];

    }

  }

  //未找到对应的cookie则返回空字符串

  return '';

}

调用的时候直接:setCookie("thisId",iid,2000);

从cookie里面取值:var thisId=getCookie("thisId");