首页 > 代码库 > js : json和 cookie 的简单操作

js : json和 cookie 的简单操作

使用 cookie,可以记录用户的最近的浏览历史 

<!DOCTYPE HTML><html lang="zh-cn"><head>    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>    <script src="http://www.mamicode.com/jquery.min.js"></script>    <script src="http://www.mamicode.com/jquery.cookie.js"></script>    <script>        $(function(){            $("#cookie").css("color", "red");            var details = $.cookie("details");            var lenth = 0;            if(details){                details = JSON.parse(details);                lenth = details.length;                $.each(details, function(index, obj){                    $("#cookie").append("<p>name : " + obj.name + ", " + "age : " + obj.age + "</p>");                });            }else{                var data = http://www.mamicode.com/[{"name" : "keen", "age" : 24},                            {"name" : "andi", "age" : 18}];                $.cookie("details", JSON.stringify(data));            }        });    </script></head><body>    <div id="cookie">cookie</div></body></html>

 

========>>>>

js : json和 cookie 的简单操作