Cookie の最近の閲覧履歴 (中国語エスケープ コード変換) 固有の実装_JavaScript スキル

WBOY
リリース: 2016-05-16 17:32:36
オリジナル
1080 人が閲覧しました

[javascript]

コードをコピー コードは次のとおりです:

/**
*pro_id: 製品 ID
*brand_name: ブランド
*pro_name: 製品 ID
*price: 価格
* カタログ: モデル
* 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:'" 価格 "',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); 
}

varhistoryJSON=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['履歴'][i]['img'],json['履歴'][i]['ファイル名'],"履歴"); 
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/' file_name; 
a.setAttribute('href',href); 
a.setAttribute("target","_blank") ; 
jQuery(a).html("

" unescape(brand_name pro_nameカタログ) "

gt;" 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( )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 = (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!='プロトタイプ'){
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') argument.callee(oo[b]);
}
}
sA.pu sh('],');
続行;
}else{
sA.push(i ':'' oo '',');
}
if(typeof oo=='object') argument.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(""),escape(""),escape("")) ;
関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!