使用 cookie,可以记录用户的最近的浏览历史
<!DOCTYPE HTML> <html lang="zh-cn"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <script src="./jquery.min.js"></script> <script src="./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 = [{"name" : "keen", "age" : 24}, {"name" : "andi", "age" : 18}]; $.cookie("details", JSON.stringify(data)); } }); </script> </head> <body> <div id="cookie">cookie</div> </body> </html>
========>>>>