Cookie操作

<script type="text/javascript">
function setCookie (name, value) {
   var Days = 30; //此 cookie 将被保存 30 天
   var exp = new Date();
   exp.setTime(exp.getTime() + 1000);
   if(value==""||value=="null"||value=="null"||value==" "){}else{
      document.cookie = name + "="+ escape(value) +";expires=Sun, 17-Jan-2038 19:14:07 GMT";
   }
}
function getCookie(name){// 使用名称参数取得Cookie值, null表示Cookie不存在
 var strCookies = document.cookie;
 var cookieName = name + "="; // Cookie名称
 var valueBegin, valueEnd, value;
 // 寻找是否有此Cookie名称
 valueBegin = strCookies.indexOf(cookieName);
 if (valueBegin == -1) return null; // 没有此Cookie
 // 取得值的结尾位置
  valueEnd = strCookies.indexOf(";", valueBegin);
 if (valueEnd == -1)
  valueEnd = strCookies.length; // 最後一个Cookie
 // 取得Cookie值
 value = strCookies.substring(valueBegin+cookieName.length,valueEnd);
 return value;
}
</script>

你可能感兴趣的:(JavaScript,sun)