cookie 最近瀏覽記錄(中文escape轉(zhuǎn)碼)具體實(shí)現(xiàn)
更新時(shí)間:2013年06月08日 11:23:07 作者:
cookie 最近瀏覽記錄(中文escape轉(zhuǎn)碼)具體實(shí)現(xiàn),需要的朋友可以參考一下
[javascript]
/**
*pro_id: 產(chǎn)品id
*brand_name : 品牌
*pro_name : 產(chǎn)品id
*price : 價(jià)格
* catalog : 機(jī)型
* 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); //添加一個(gè)新的記錄
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;}
}
}
//添加一個(gè)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'"+" width='90' height='50' /><h3> "+unescape(brand_name+pro_name+catalog)+"</h3><span class='price'>"+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;
}
}
加一個(gè)cookie
addHistory("<%=uuid%>",escape("<%=factoryname%>"),escape("<%=name%>"),escape("<%=price%>"),escape("<%=catalogname%>"),escape("<%=img%>"),escape("<%=file_name%>"));
復(fù)制代碼 代碼如下:
/**
*pro_id: 產(chǎn)品id
*brand_name : 品牌
*pro_name : 產(chǎn)品id
*price : 價(jià)格
* catalog : 機(jī)型
* 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); //添加一個(gè)新的記錄
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;}
}
}
//添加一個(gè)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'"+" width='90' height='50' /><h3> "+unescape(brand_name+pro_name+catalog)+"</h3><span class='price'>"+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]
復(fù)制代碼 代碼如下:
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;
}
}
加一個(gè)cookie
復(fù)制代碼 代碼如下:
addHistory("<%=uuid%>",escape("<%=factoryname%>"),escape("<%=name%>"),escape("<%=price%>"),escape("<%=catalogname%>"),escape("<%=img%>"),escape("<%=file_name%>"));
相關(guān)文章
不錯(cuò)的用resizeTo和moveTo兩個(gè)函數(shù)實(shí)現(xiàn)窗口的“打乒乓球”效果
不錯(cuò)的用resizeTo和moveTo兩個(gè)函數(shù)實(shí)現(xiàn)窗口的“打乒乓球”效果...2007-08-08Openlayers實(shí)現(xiàn)地圖的基本操作
這篇文章主要為大家詳細(xì)介紹了Openlayers實(shí)現(xiàn)地圖的基本操作,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09微信小程序用戶授權(quán)獲取手機(jī)號(hào)(getPhoneNumber)
這篇文章主要給大家介紹了關(guān)于微信小程序用戶授權(quán)獲取手機(jī)號(hào)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03Javascript 使用function定義構(gòu)造函數(shù)
Javascript并不像Java、C#等語言那樣支持真正的類。但是在js中可以定義偽類。做到這一點(diǎn)的工具就是構(gòu)造函數(shù)和原型對(duì)象。首先介紹js中的構(gòu)造函數(shù)。2010-02-02JavaScript中html畫布的使用與頁面存儲(chǔ)技術(shù)詳解
這篇文章主要介紹了JavaScript中html畫布的使用與頁面存儲(chǔ)技術(shù),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-08-08javascript與webservice的通信實(shí)現(xiàn)代碼
關(guān)于javascript與webservice的通信,從理論上來說實(shí)現(xiàn)應(yīng)該不難,主要是將服務(wù)器端的xml數(shù)據(jù)進(jìn)行一個(gè)簡單的處理然后以一種適當(dāng)?shù)男问秸宫F(xiàn)成來。2010-12-12JavaScript實(shí)現(xiàn)AOP詳解(面向切面編程,裝飾者模式)
下面小編就為大家分享一篇JavaScript實(shí)現(xiàn)AOP的方法(面向切面編程,裝飾者模式),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2017-12-12