首頁 > web前端 > js教程 > 主體

Cookie 最近瀏覽記錄(中文escape轉碼)具體實作_javascript技巧

WBOY
發布: 2016-05-16 17:32:36
原創
1081 人瀏覽過

[javascript]

複製程式碼 程式碼如下:

/**
*pro_id: 產品id 
*brand_name : 品牌
*pro_name : 產品id 
*price : 價格
* catalog : 機型
* img : 圖片
* catalog : 機型
* img : 圖片
: 檔名
*/ 
var addHistory=function(pro_id,brand_name,pro_name,price,catalog,img,file_name){  🎜> 
    var stringHistory=""!=stringCookie?stringCookie:"{history:[]}"; 
    var json=new JSON(stringHistory); 
    var pro_ids = '' ; 
    jQuery.each(json['history'],function(i,val){ 
        pro_ids =json['history'][i].pro_id "," ;  pro_ids =json['history'][i].pro_id "," ;  
    if(jQuery.trim(pro_id)=='' || pro_ids.indexOf(pro_id)==-1){ 
          ,pro_name:'" pro_name"',price:'"價"',catalog:'"目錄"',img:'" img "',file_name:'" file_name "'}"; 
            json['history'].push(e);   // 新增一個新的記錄
            setCookie('history',json.toString(),30); 
    } 

//顯示歷史記錄 
var DisplayHistory=function(){ 
    var p_ele​​=document.getElementById('history'); 
     while (p_ele.firstChild) { 
      p_ele.removeChild(p_ele.firstChild); 
     } 

    var HistoryJSON=getCookie('history'); 
    var json=new JSON(historyJSON); 
    var displayNum=6; 
    for(i=json['history'].length-1;i>=0;i--){ 
        addLi(json['history'][i]['pro_id'],json[ '歷史'][i]['品牌名稱'],json['歷史'][i]['pro_name'],json['歷史'][i]['價格'],json['歷史'] [ i]['目錄'],json['歷史'][i]['img'],json['歷史'][i]['檔案名稱'],"歷史"); 
        displayNum--; 
        if(displayNum==0){break;} 
    } 

//新增一. file_name,pid){ 
    var a=document.createElement('a'); 
    var href='//m.sbmmt.com/proDetail/' file_name; 
    a.setAttribute('href',href); 
    a.setAttribute("target","_blank") ; 
    jQuery(a).html("Cookie 最近瀏覽記錄(中文escape轉碼)具體實作_javascript技巧

" unescape(brand_name pro_name Catalog) "

" unescape(price) "") ; 
    var li=document.createElement('li'); 
    li.appendChild(a); 
    jQuery(li).appendTo("#" pid) ; 

//新增cookie 
var setCookie=function(c_name,value,expiredays) 

   ) ) ) expiredays) 
    cookieVal=c_name "= escape(value) ((expiredays==null) ? "" : ";path=/;expires=" exdate.toGMTString()); 
ookie = cookieVal; 

//取得cookie 
function getCookie(c_name) 

    if (document.cookie.length>0)       if (c_start!=-1) 
        {        c_end=document.cookie.indexOf(";",c_start )
        if (c_end==-1) c_end=document.cookie.length 
        return unescape(document.cookie.string(c_startc. 🎜>      } 
    return ""

//清除cookie  
function DeleteCookie(){ 
     setCookie('history',"{history:[ ]}",30);
json.js
[javascript]
複製程式碼 程式碼如下:

var JSON = function(sJSON){ 
 this.objType = (typeof sJSON); 
if(this.objType=='string' && ''==sJSON){ 
      sJSON = '{history:[]}' ; 

    this.self = []; 
    (函數(s,o){ 
       為(var i in o){ 
         o[i]) 
            };})(this,(this.objType=='string')?eval('0,' sJSON):sJSON); 

JSON.prototype = { 
    toString:function(){ 
        return this.getString(); 
    }, 
    valueOf:function(){ 
        return this.getString(); 
    }, 
    getString:function(){ 
        var sA = []; 
        (function(o){ 
            var oo = null;                 位於if (o.hasOwnProperty(i ) && i!='原型'){ 
                   oo = o[i]; 
                       sA.push(i ':[' );                              if(oo.hasOwnProperty(b) && b!='原型'){ 
                                sA.push(oo[b] ','); 🎜>                                if(typeof oo[b ] =='object') argument.callee(oo[b]); 
                        } 
                       sA.push( '], ');    
                    }其他{ 
                      sA.push(i ':'' oo '','); 
    }               if(typeof oo=='object')arguments.callee(oo) ; 
       🎜>            sA.push('},'); 
        })(this.self); 
        return sA.slice(0).join('').replace(/[object object],/ig,'').replace(/,}/g,'}').replace(/,] /g,']').slice(0,-1); 
    }, 
    Push:function(sName,sValue){ 
        this.self[sName] = sValue; 
        this[sName] = sValue; 
    } 
}

加一個cookie
複製程式碼 代碼如下:

代碼如下:",escape(""),escape(""),escape(""),escape(" "),escape(""),escape(""));
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!