Home  >  Q&A  >  body text

Cookies are set but not displayed?

document.cookie="userId=828";

document.cookie="userName=hulk";

//Get cookie string

var strCookie=document.cookie;

//Cut multiple cookies into multiple name/value pairs

var arrCookie=strCookie.split("; ");

var userId;

//Traverse the cookie array and process each cookie pair

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

var arr=arrCookie[i].split("=");

//Find the cookie named userId and return its value

if("userId"==arr [0]){

userId=arr[1];

break;

}

}

alert(userId) ;


girlgirl2619 days ago1375

reply all(2)I'll reply

  • phpcn_u15277

    phpcn_u152772017-08-18 17:03:44

    Cleared cache, still not working

    reply
    0
  • ringa_lee

    ringa_lee2017-08-18 16:16:26

    Check if there is browser cache

    reply
    0
  • Cancelreply