쿠키 최근 검색 기록(중국어 이스케이프 트랜스코딩) 특정 구현_javascript 기술

WBOY
풀어 주다: 2016-05-16 17:32:36
원래의
1080명이 탐색했습니다.

[javascript]

코드 복사 코드는 다음과 같습니다.

/**
*pro_id: 제품 ID
*brand_name: 브랜드
*pro_name: 제품 ID
*가격: 가격
* 카탈로그: 모델
* img: 사진
*file_name: 파일명
*/ 
var addHistory=function(pro_id,brand_name,pro_name,price,catalog,img,file_name){  
    stringCookie=getCookie('history'); 
    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 "," ; 
    }) ; 
    if(jQuery.trim(pro_id)=='' || pro_ids.indexOf(pro_id)==-1){ 
            var e="{pro_id:" pro_id ",brand_name:'" 브랜드_이름 "' ,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[ 'history'][i]['brand_name'],json['history'][i]['pro_name'],json['history'][i]['price'],json['history'][ i]['카탈로그'],json['history'][i]['img'],json['history'][i]['file_name'],"history"); 
        displayNum--; 
        if(displayNum===0){break;} 
    } 

//添加一个cookie    
var addLi=function(pro_id,brand_name,pro_name,price,catalog,img, file_name,pid){ 
    var a=document.createElement('a'); 
    var href='//m.sbmmt.com/proDetail/' 파일_이름; 
    a.setAttribute('href',href); 
    a.setAttribute("target","_blank") ; 
    jQuery(a).html("

" unescape(brand_name pro_name 카탈로그) "

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

//添加cookie 
var setCookie=function(c_name,value,expiredays) 

    var exdate=new Date() 
    exdate.setDate(exdate.getDate( ) 만료일) 
    cookieVal=c_name "=" escape(value) ((expiredays==null) ? "" : ";path=/;expires=" exdate.toGMTString()); 
    document.cookie=cookieVal; 

//获取cookie 
function getCookie(c_name) 

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

// 清除cookie  
function DeleteCookie(){ 
     setCookie('history',"{history:[]}",30); 

 

json.js
[javascript]
코드 복사 코드는 다음과 같습니다.

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

    this.self = []; 
    (함수(s,o){ 
        for(var i in o){ 
            o.hasOwnProperty(i)&&(s[i]=o[i],s.self[i]= 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 = []; 
        (기능(o){ 
            var oo = null; 
           sA.push('{'); 
           for(var i in o){ 
              if (o.hasOwnProperty(i ) && i!='prototype'){ 
                   oo = o[i]; 
                 if(oo 인스턴스 오브 어레이){ 
                      sA.push(i ': ['); 
                      for(var b in oo){ 
                           if(oo.hasOwnProperty(b) && b!='prototype'){ 
                            sA.push(oo[b] ','); 
                               if(typeof oo[b ]=='object') 인수.callee(oo[b]); 
                         } 
                   } 
                      sA.push ('],'); 
                      계속; 
                  }else{ 
                      sA.push(i ':'' oo '','); 
                } 
            }
            sA.push('},'); 
        })(this.self); 
        return sA.slice(0).join('').replace(/[객체 객체],/ig,'').replace(/,}/g,'}').replace(/,] /g,']').slice(0,-1); 
    }, 
    push:function(sName,sValue){ 
        this.self[sName] = sValue; 
        this[sName] = sValue; 
    } 
}

쿠키 추가
코드 복사 코드는 다음과 같습니다.

addHistory("<%=uuid%>",escape("<%=factoryname%>"),escape("<%=name%>"),escape("<% =price% >"),escape("<%=카탈로그 이름%>"),escape("<%=img%>"),escape("<%=file_name%>")) ;
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!