国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

cookie 最近瀏覽記錄(中文escape轉碼)具體實現

2024-05-06 15:46:48
字體:
來源:轉載
供稿:網友
cookie 最近瀏覽記錄(中文escape轉碼)具體實現,需要的朋友可以參考一下

[javascript]

復制代碼 代碼如下:


/**
*pro_id: 產品id
*brand_name : 品牌
*pro_name : 產品id
*price : 價格
* catalog : 機型
* 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:'"+brand_name+"',pro_name:'"+pro_name+"',price:'"+price+"',catalog:'"+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]['catalog'],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='/proDetail/'+file_name;
a.setAttribute('href',href);
a.setAttribute("target","_blank") ;
jQuery(a).html("<img src='"+unescape(img)+"' onerror="+"this.src='/images/nopic.gif'"+" /><h3> "+unescape(brand_name+pro_name+catalog)+"</h3><span>"+unescape(price)+"</span>") ;
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()+expiredays)
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 = (typeof sJSON);
if(this.objType=='string' && ''==sJSON){
sJSON = '{history:[]}' ;
}
this.self = [];
(function(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 = [];
(function(o){
var oo = null;
sA.push('{');
for(var i in o){
if(o.hasOwnProperty(i) && i!='prototype'){
oo = o[i];
if(oo instanceof Array){
sA.push(i+':[');
for(var b in oo){
if(oo.hasOwnProperty(b) && b!='prototype'){
sA.push(oo[b]+',');
if(typeof oo[b]=='object') arguments.callee(oo[b]);
}
}
sA.push('],');
continue;
}else{
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

復制代碼 代碼如下:


addHistory("<%=uuid%>",escape("<%=factoryname%>"),escape("<%=name%>"),escape("<%=price%>"),escape("<%=catalogname%>"),escape("<%=img%>"),escape("<%=file_name%>"));

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 金湖县| 马公市| 清流县| 延长县| 忻州市| 呼图壁县| 曲水县| 平凉市| 洪洞县| 格尔木市| 老河口市| 繁昌县| 阿合奇县| 南和县| 平原县| 庐江县| 林口县| 米林县| 南靖县| 甘泉县| 安徽省| 灵宝市| 托克逊县| 河池市| 都兰县| 澄江县| 三都| 阿拉善盟| 岳阳县| 吉安县| 油尖旺区| 巢湖市| 双牌县| 梁山县| 竹山县| 大港区| 余姚市| 祁阳县| 莱阳市| 宾川县| 马尔康县|