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

首頁 > 語言 > JavaScript > 正文

js 實現瀏覽歷史記錄示例

2024-05-06 16:04:21
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了如何使用js實現瀏覽歷史記錄,需要的朋友可以參考下

先必須要引用一個js jquery.cookie.js

1,首先寫入jsCookied

復制代碼 代碼如下:


//瀏覽記錄 寫入JSCookied 開始
var img=$("#ProductImgurl").attr("jqimg");
var name=$("#ProductDetail_ctl00_LabelName").text();
var url=location.href;
var price=$("#ProductDetail_ctl00_LabelShopPrice").text();
var sellcount=$("#ProductDetail_ctl00_lblSaleNumber").text();
var hc=img+"|"+name+"|"+url+"|"+price+"|"+sellcount;
if($.cookie("history")!=null)
{
if($.cookie("history").indexOf(name)==-1)
{

$.cookie("history",hc+"*"+$.cookie("history"),{expires:8,domain:'.groupfly.com',path:"http://www.survivalescaperooms.com/"});
}
}
else
{
$.cookie("history",hc,{expires:8,domain:'.groupfly.com',path:"http://www.survivalescaperooms.com/"});
}
//瀏覽記錄 寫入JSCookied 結束


2,然后再讀取Cookied

復制代碼 代碼如下:


<script type="text/javascript" charset="utf-8">
//讀取cookied歷史記錄
$(function(){

var hc=$.cookie("history");
if(hc!=null)
{
if(hc.indexOf("*")!=-1)
{
var splithtml=hc.split("*");
var xhtml=new Array();
var hlength=splithtml.length;
if(parseInt(hlength)>4)
hlength=4;
for(var i=0;i<parseInt(hlength);i++)
{
xhtml.push('<div><div><a href="'+splithtml[i].split("|")[2]+'">'+splithtml[i].split("|")[1].substr(0, 17)+'</a></div>');
xhtml.push('<div><a href="'+splithtml[i].split("|")[2]+'"><img src="'+splithtml[i].split("|")[0]+'_160x160.jpg" /></a><p>¥'+splithtml[i].split("|")[3]+'</p></div>');
xhtml.push('<div><span>已銷售<b>'+splithtml[i].split("|")[4]+'</b>筆</span><a href="'+splithtml[i].split("|")[2]+'">再看看</a></div></div>');
}
xhtml.push('<div><a href="javascript:clearcookied();">清空記錄</a></div>');
$("#MyHistory").append(xhtml.join(""));
}
else{
var xhtml=new Array();
xhtml.push('<div><div><a href="'+hc.split("|")[2]+'">'+hc.split("|")[1].substr(0, 17)+'</a></div>');
xhtml.push('<div><a href="'+hc.split("|")[2]+'"><img src="'+hc.split("|")[0]+'_160x160.jpg" /></a><p>¥'+hc.split("|")[3]+'</p></div>');
xhtml.push('<div><span>已銷售<b>'+hc.split("|")[4]+'</b>筆</span><a href="'+hc.split("|")[2]+'">再看看</a></div></div>');
xhtml.push('<div><a href="javascript:clearcookied();">清空記錄</a></div>');
$("#MyHistory").append(xhtml.join(""));
}
}
else
{
$("#MyHistory").append("<li>暫無瀏覽記錄</li>");
}
});

function clearcookied()
{
$.cookie('history',null,{expires:1,domain:'.nrqiang.com'});
$("#MyHistory").html("<li>暫無瀏覽記錄</li>");
}
$(function() {
$("img").each(function(){$(this).attr("src",$(this).attr("original"));});
});
</script>

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

圖片精選

主站蜘蛛池模板: 建阳市| 抚州市| 三门峡市| 道孚县| 万荣县| 高尔夫| 和静县| 竹北市| 望奎县| 田阳县| 黄龙县| 新民市| 永泰县| 木兰县| 枞阳县| 兴化市| 安达市| 三都| 自治县| 东阿县| 白沙| 舞阳县| 兰溪市| 秦皇岛市| 阆中市| 西乌珠穆沁旗| 蓝山县| 津南区| 阜新市| 岳池县| 长岛县| 怀远县| 芷江| 竹北市| 阿坝县| 抚顺市| 辉南县| 太康县| 株洲市| 长顺县| 蒲城县|