cookie存储记录

////// 历史记录
        $(function () {
            // 标题
            var art_title = $("#Lbl_Hotel_Name").text();
            // 得到当前路径
            var art_url = document.URL;// 页面地址
            //得到code;
            var Art_code = art_url.substring(art_url.indexOf('?') + 1, art_url.length);
            //  var art_code = $("#yincang").val();
            // 价格 ;
            var art_price = $("#Hotelprice").text();
            //币种
            var art_Money = $("#Money").text();
            // 图片;
            var art_im = $("#images_small li:first img ").attr("src");
            var src = art_im.substring(0, art_im.length - 4);
            var hz = art_im.substring(art_im.length - 4, art_im.length);
            var art_img = src + "s" + hz;
            // 星级;
            var art_start = $("#HotelStar").attr("src");
            // 初始可以插入cookie 信息;
            var len = 0;
            var canAdd = true;

            var hisArt = $.cookie("hisArt");

            if (hisArt) {
                hisArt = eval("(" + hisArt + ")");
                len = hisArt.length;
            }
            /////////////////
            // 如果浏览信息已经存在 则终止;
            //$(hisArt).each(function () {

            //    if (this.title = art_title) {
            //        canAdd = false;// 已经存在;
            //        return false;
            //    }

            //});

            if (canAdd == true) {
                // 构建json 数据
                var json = "[";
                var start = 0;
                if (len > 5) {
                    start = 1;
                }
                for (var i = start; i < len; i++) {
                    json = json + "{\"title\":\"" + hisArt[i].title + "\",\"Money\":\"" + hisArt[i].Money + "\",\"HotelPrice\":\"" + hisArt[i].HotelPrice + "\",\"HotelImg\":\"" + hisArt[i].HotelImg + "\",\"Img_Start\":\"" + hisArt[i].Img_Start + "\",\"Code\":\"" + hisArt[i].Code + "\"},";
                }
                json = json + "{\"title\":\"" + art_title + "\",\"Money\":\"" + art_Money + "\",\"HotelPrice\":\"" + art_price + "\",\"HotelImg\":\"" + art_img + "\",\"Img_Start\":\"" + art_start + "\",\"Code\":\"" + Art_code + "\"}]";

                $.cookie("hisArt", json, { path: "/" }, { expires: 1 });
            }
        });

        $(function () {
            //清空历史记录
            //$.cookie("hisArt", null);
            var json = eval("(" + $.cookie("hisArt") + ")");
            var list = "";
            for (var i = 0; i < json.length - 1; i++) {
                list = list + "<div class='div1'><dl><dt><a href='<%=CSweb%>Templete/HotelOutside/HotelInfo.aspx?Code=" + json[i].Code + "'><img src=" + json[i].HotelImg + "  /></a></dt><dd ><p class='p1'><a href='<%=CSweb%>Templete/HotelOutside/HotelInfo.aspx?Code=" + json[i].Code + "'>" + json[i].title + "</a></p>" + "<p class='p2'><span style='margin_right:34px'>4星</span>" + json[i].Money + json[i].HotelPrice + "</p></dd></dl><div><a href='#3'><img src=/images/xj_bi.jpg' /></a></div></div>"

            }
            $("#list").html(list);

        });

取:

$(function () {
            //清空历史记录
            //$.cookie("hisArt", null);
            var json = eval("(" + $.cookie("hisArt") + ")");
            //alert(json);
            var list = "<div class='LickTit' > <span class='LickIcon'></span><h2 >我的浏览记录</h2></div>";
            for (var i = 0; i < json.length; i++) {
                list = list + "<div class='Lishi'><div class='Lishiimg'><a href='<%=CSweb%>Templete/HotelOutside/HotelInfo.aspx?Code=" + json[i].Code + "'><img src=" + json[i].HotelImg + " /></a> </div> <div class='Lishifont'> <p class='LishiP'> <a href='<%=CSweb%>Templete/HotelOutside/HotelInfo.aspx?Code=" + json[i].Code + "' class='Lishihref'>" + json[i].title + "</a></p><p class='LishiP'><span class='lsspan'>4星</span> </p> <p class='LishiP LishiP_bt'> <span class='lsspan'>" + json[i].Money + json[i].HotelPrice + "</span><a href='<%=CSweb%>Templete/HotelOutside/HotelInfo.aspx?Code=" + json[i].Code + "' class='lsahrf'>查看</a> </p> <a href='javascript:;' class='lishiNot'></a></div> </div> "
            }
            $("#list").html(list);


            $("#<%=cbl_Facility.ClientID%>").change(function () {
            });




        });

引用资源:

<script type="text/javascript" src="../js/jq.page/jquery.cookie.js"></script>

 

posted @ 2013-12-14 17:06  觉信  阅读(321)  评论(0编辑  收藏  举报