对document.cookie的操作汇集

1.添加一个新的  
  document.cookie="新的name=value"  
   
  2.修改原有的  
  document.cookie="原有的name=value"  
   
  3.查询某个name的值  
  <script>  
  alert(getCookieByName("login"))  
  alert(getCookieByName("login2"))  
  function   getCookieByName(name){  
  /********(qiushuiwuhen)***********/  
  var   arr,reg=new   RegExp("(^|   )"+name+"=([^;]*)(;|$)");  
  if(arr=document.cookie.match(reg))  
  return   arr[2];  
  else  
  return   null  
  }  
  </script>  
   
  4.对中文和;的处理  
  一般用escape,如  
  document.cookie="name="+escape(含中文的字符串)  
  但提交给php,asp等无法处理,所以建议使用urlencoding,如  
   
  <script   language="vbscript">  
  function   urlencoding(vstrin)  
  dim   i,strreturn  
          strreturn   =   ""  
          for   i   =   1   to   len(vstrin)  
                  thischr   =   mid(vstrin,i,1)  
                  if   abs(asc(thischr))   <   &hff   then  
                          strreturn   =   strreturn   &   thischr  
                  else  
                          innercode   =   asc(thischr)  
                          if   innercode   <   0   then  
                                  innercode   =   innercode   +   &h10000  
                          end   if  
                          hight8   =   (innercode     and   &hff00)/   &hff  
                          low8   =   innercode   and   &hff  
                          strreturn   =   strreturn   &   "%"   &   hex(hight8)   &     "%"   &   hex(low8)  
                  end   if  
          next  
          urlencoding   =   strreturn  
  end   function  
  </script>  
  <script   language=javascript>  
  document.cookie="name="+urlencode(含中文的字符串)  
  </script>  
  这样提交到php,asp等就可以用urlcode解析出来了了  
   
   
   
  现在最大问题是如何删除一个cookie? 

document.cookie="";可以删除 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值