午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    js產(chǎn)品比較代碼
    來源:易賢網(wǎng) 閱讀:1092 次 日期:2014-08-13 16:40:02
    溫馨提示:易賢網(wǎng)小編為您整理了“js產(chǎn)品比較代碼”,方便廣大網(wǎng)友查閱!

    通過js javascript對cookie進行操作記錄,然后對產(chǎn)品進行對比。

    本代碼用到jquery。請確認有jquery 整體代碼如下: 在線測試

    <script language="javascript">

    $(function(){

        var show_div = $("<div id='forasp_list'></div>");

     $("body").append(show_div); 

     $("#forasp_list").css({position:"relative",width:"200px",height:"auto",border:"solid thin #000 1px;"}).offset({top:100,left:300}).hide();

     $(window).scroll(function(){move();});

    });

    function add(pid,name){//內(nèi)容用#分割,內(nèi)容組用","分割

     //alert(unescape(escape(name)));

     var max_num = 4;

     var c_str = get_ck();

     var c_str_ = "";

     var t_c_arr = new Array();

     var t_c_arr_ = new Array();

     var flag = true;

     show();

     if(c_str.indexOf("#")==-1){

      c_str_ = pid+"#"+escape(name);

     }else{

       t_c_arr = c_str.split(",");

       var t_c_num = t_c_arr.length;

       for(var i=0;i<t_c_num;i++){

       t_c_arr_ = t_c_arr[i].split("#");

       if(pid==t_c_arr_[0]){alert("已經(jīng)添加該產(chǎn)品!");show();flag=false;break;}

       c_str_ = c_str_+t_c_arr_[0]+"#"+t_c_arr_[1]+",";

       }

     if(!flag)return;

     if(t_c_num>=max_num){alert("最多比較四個產(chǎn)品");return;}

     c_str_ = c_str_+pid+"#"+escape(name);

      } 

    set_ck(c_str_);

    show();

    }

    function del(pid){

       var c_str = get_ck();

       var c_str_="";

       if(pid==0){//如果是全部清空

         c_str_ = "";

       }else{

       c_str = get_ck();

       

      if(c_str!=""){

       t_c_arr = c_str.split(",");

          for(var i=0;i<t_c_arr.length;i++){

      var t_c_arr_ = t_c_arr[i].split("#");

       if(pid!=t_c_arr_[0])c_str_ = c_str_+","+t_c_arr_[0]+"#"+t_c_arr_[1];

       }

       if(c_str_!="")c_str_=c_str_.substr(1,c_str_.length-1);

      }

     }

     set_ck(c_str_);

     set_htmlin();

    }//原載于:學習www.網(wǎng)for站asp制.cn作

    function set_htmlin(){

      var html_="";

       c_str = get_ck();

       $("#forasp_list").html("");

       if(c_str!=""){

       t_c_arr = c_str.split(",");

       t_c_num = t_c_arr.length;

       for(var i=0;i<t_c_num;i++){

     t_c_arr_ = t_c_arr[i].split("#");

     html_+=unescape(t_c_arr_[1])+"---<a href='#' onclick='del("+t_c_arr_[0]+")'>刪除</a><br>";

        }

       }

        html_+="<br><a href='#' onclick='compair()'>比較</a> <a href='#' onclick='del(0);'>清空</a> <a href='#' onclick='hid();'>隱藏</a>";

       $("#forasp_list").html(html_);

    }

    function show(){

     set_htmlin();

     $("#forasp_list").show();

    }

    function hid(){

     $("#forasp_list").hide();

    }

    function move(){//www.forasp.cn原創(chuàng)

     var scrollPos;

    if(typeof window.pageYOffset!="undefined")

    {

    scrollPos = window.pageYOffset;

    }

    else if (typeof document.compatMode != "undefined" && document.compatMode != "BackCompat")

    {

    scrollPos = document.documentElement.scrollTop;

    }

    else if (typeof document.body != "undefined")

    {

    scrollPos = document.body.scrollTop;

    }

    var obj =$("#forasp_list");

    var op = obj.position().top;

    obj.offset({"top":100+scrollPos});

    show();

    }

    function get_ck(){

     var temp = document.cookie;

     if(temp.indexOf("foraspcn_=")!=-1){

     return temp.split("foraspcn_=")[1];

     }else{

      return "" ;

     }

    }

    function set_ck(temp){

     var date=new Date();

      if(temp!=""){

     date.setDate(date.getDate()+1);

     document.cookie="foraspcn_="+temp+"; expires="+date.toGMTString();

     }else{

     date.setDate(date.getDate()-1);

     document.cookie="foraspcn_="+temp+"; expires="+date.toGMTString();

     }

    }function compair(){

       var c_str = get_ck();

       var c_str_="";

        if(c_str==""){alert("至少兩個選項!");return;}

      t_c_arr = c_str.split(",");

      if(t_c_arr.length<=1){alert("至少兩個選項!");return;}

          for(var i=0;i<t_c_arr.length;i++){

      var t_c_arr_ = t_c_arr[i].split("#");

       c_str_ = c_str_+","+t_c_arr_[0];

       }

     window.open("?"+c_str_);

    }

    </script>

    更多信息請查看IT技術(shù)專欄

    更多信息請查看腳本欄目
    易賢網(wǎng)手機網(wǎng)站地址:js產(chǎn)品比較代碼

    2025國考·省考課程試聽報名

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)