1. //设置cookie
    2. document.cookie="address=1";
    1. //获取cookie的值
    2. document.cookie="userId=828";
    3. document.cookie="userName=hulk";
    4. //获取cookie字符串
    5. var strCookie=document.cookie;
    6. //将多cookie切割为多个名/值对
    7. var arrCookie=strCookie.split("; ");
    8. var userId;
    9. //遍历cookie数组,处理每个cookie对
    10. for(var i=0;i<arrCookie.length;i++){
    11. var arr=arrCookie[i].split("=");
    12. //找到名称为userId的cookie,并返回它的值
    13. if("userId"==arr[0]){
    14. userId=arr[1];
    15. break;
    16. }
    17. }
    18. alert(userId);
    19. //输出828