js操作cookie

1.设置cookie

      function setCookie(cname, cvalue, exdays)
      {
        var d = new Date();
        d.setTime(d.getTime() + (exdays*24*60*60*1000));
        var expires = "expires="+ d.toUTCString();
        document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
      }

2.获取cookie

      function getCookie(cname)
      {
        var name = cname + "=";
        var decodedCookie = decodeURIComponent(document.cookie);
        var ca = decodedCookie.split(';');
        for(var i = 0; i 

3.综合代码


  
    cookie
  
  
    
  

你可能感兴趣的:(js操作cookie)