/**
*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='/proDetail/' file_name;
a.setAttribute('href',href);
a.setAttribute("target","_blank") ;
jQuery(a).html("
" 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(""));