Chinaunix首页 | 论坛 | 博客
  • 博客访问: 99430
  • 博文数量: 33
  • 博客积分: 101
  • 博客等级: 民兵
  • 技术积分: 185
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-17 22:42
文章分类
文章存档

2013年(1)

2012年(16)

2011年(16)

我的朋友

分类:

2011-12-01 23:51:38

创建 share_position_cookie.txt  


$(function() {
    //初始化获取名为hisArt的cookie (里面存放的是json对象)
      var json = eval("("+$.cookie("hisArt")+")");
      var list = "";
      //如果有缓存,则取出遍历
      if(json != null){
                //css   
            $("#cookieList").css({display: ""});
            $("#clearBtn").css({display: ""});
            //document.getElementById("demo").style.display = "";
           
            var boarddiv ="";
            for(var i=0; i                //list = list + "
  • "+json[i].title+"
  • ";
                     boarddiv = boarddiv + "
    ";
                }
                //构建页面布局
                $("#list").html(boarddiv);
           
            }else{
               //如果不存在则清除记录历史的位置
                     $("#cookieList").css({display: "none"});
                     $("#clearBtn").css({display: "none"});
                }
           //创建
            createHistory();
    });





    ——————————————————————————--------

    function createHistory(){

        //获取页面元素
        var art_title = $("#positionName").val(); //文章标题
        art_title = art_title.replace("'","");

        var art_location = $("#location").val();
        art_location = art_location.replace("\'","");
       
        var art_salary =  $("#salary").val();
        art_salary = art_salary.replace("\'","");
       
        var art_reward = $("#reward").val();
        art_reward = art_reward.replace("\'","");
       
        var art_url = document.URL; //页面地址


        var canAdd = true; //初始可以插入cookie信息
       
        var hisArt = $.cookie("hisArt");
       
        var len = 0;

        //初始化长度
        if(hisArt){
            hisArt = eval("("+hisArt+")");
            len = hisArt.length;
        }

       
        //是否是重复访问
          var hisArt_json = eval("("+$.cookie("hisArt")+")");
            var list = "";
            if(hisArt_json != null){
    //如果cookie中存在该页面访问过的记录,则不放入cookie
            for(var i=0; i            if(art_title == hisArt_json[i].title){
                    canAdd == false;
                      return false;
                    }
            }
           
         }
       

        //添加
        if(canAdd == true){

               var json = "[";
                var start = 0;
                var endJson = "]";
                if(len>5){start = 1;}
               
            if(len == 3){

                //5
                //art_title art_url
                var title =  art_title;
                var url = art_url;
                var salary = art_salary;
                var location = art_location;
                var reward = art_reward;
                 
                 
                //0 1 2 3 4 只记录最近访问的4个历史
                for(var i=start;i<3;i++){
                   
                     if(i == len -1){
                            json = json + "{\"title\":\""+title+"\",\"url\":\""+url+"\",\"location\":\""+location+"\",\"salary\":\""+salary+"\",\"reward\":\""+reward+"\"}";
                        }
                            else{
                            json = json + "{\"title\":\""+title+"\",\"url\":\""+url+"\",\"location\":\""+location+"\",\"salary\":\""+salary+"\",\"reward\":\""+reward+"\"},";
                         }
                       
                      title = hisArt[i].title;
                      url = hisArt[i].url;
                      salary = hisArt[i].location;
                      location =hisArt[i].salary;
                      reward = hisArt[i].reward;
                }

            //    alert(json + "_____________________p2");

            }else{
    //。如果多了重新替换
                    if(len > 0){
                    json = json + "{\"title\":\""+art_title+"\",\"url\":\""+art_url+"\",\"location\":\""+art_location+"\",\"salary\":\""+art_salary+"\",\"reward\":\""+art_reward+"\"},";
                   
                     }
                    else{
                        json = json + "{\"title\":\""+art_title+"\",\"url\":\""+art_url+"\",\"location\":\""+art_location+"\",\"salary\":\""+art_salary+"\",\"reward\":\""+art_reward+"\"}";
                       
                    }
                    
                    for(var i=start;i                    if(i == len -1){
                        json = json + "{\"title\":\""+hisArt[i].title+"\",\"url\":\""+hisArt[i].url+"\",\"location\":\""+hisArt[i].location+"\",\"salary\":\""+hisArt[i].salary+"\",\"reward\":\""+hisArt[i].reward+"\"}";
                        
                            }
                        else{
                        json = json + "{\"title\":\""+hisArt[i].title+"\",\"url\":\""+hisArt[i].url+"\",\"location\":\""+hisArt[i].location+"\",\"salary\":\""+hisArt[i].salary+"\",\"reward\":\""+hisArt[i].reward+"\"},";
                            }
                    }

                    //alert(json + "_____________________p2");
                    //alert(json + "_____________________p3");
            }
                    json = json + endJson;
                  //  alert(json);
    /**
    *
    * 如果你有其他页面需要共享该cookie,则必须设置该cookie的作用域,否则获取不到。
    */
                    $.cookie("hisArt",json,{expires:30, path: '/'});
         
        }
        }
     ------------------------------------
    function clearHistory(){
     
        if($.cookie("hisArt") == null){
           
                alert("您浏览职位的历史记录已清空");
               
            }else{
                  $.cookie("hisArt",null, { path: '/' });
                 $("#clearBtn").css({display: "none"});
                  $("#list").html("
    您已清空最近浏览过的职位
    ");
                }
         
        }

    阅读(2129) | 评论(0) | 转发(0) |
    给主人留下些什么吧!~~