先必须要引用一个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:"/"});
}
}
else
{
$.cookie("history",hc,{expires:8,domain:'.groupfly.com',path:"/"});
}
//浏览记录 写入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 class="tuijian"><div class="tjname"><a href="'+splithtml[i].split("|")[2]+'">'+splithtml[i].split("|")[1].substr(0, 17)+'</a></div>');
xhtml.push('<div class="tjimga"><a href="'+splithtml[i].split("|")[2]+'"><img src="/UploadFiles/2021-04-02/'+splithtml[i].split(">xhtml.push('<div class="otherInfo clearfix"><span>已销售<b>'+splithtml[i].split("|")[4]+'</b>笔</span><a href="'+splithtml[i].split("|")[2]+'">再看看</a></div></div>');
}
xhtml.push('<div class="tr"><a href="javascript:clearcookied();">清空记录</a></div>');
$("#MyHistory").append(xhtml.join(""));
}
else{
var xhtml=new Array();
xhtml.push('<div class="tuijian"><div class="tjname"><a href="'+hc.split("|")[2]+'">'+hc.split("|")[1].substr(0, 17)+'</a></div>');
xhtml.push('<div class="tjimga"><a href="'+hc.split("|")[2]+'"><img src="/UploadFiles/2021-04-02/'+hc.split(">xhtml.push('<div class="otherInfo clearfix"><span>已销售<b>'+hc.split("|")[4]+'</b>笔</span><a href="'+hc.split("|")[2]+'">再看看</a></div></div>');
xhtml.push('<div class="tr"><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>
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:"/"});
}
}
else
{
$.cookie("history",hc,{expires:8,domain:'.groupfly.com',path:"/"});
}
//浏览记录 写入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 class="tuijian"><div class="tjname"><a href="'+splithtml[i].split("|")[2]+'">'+splithtml[i].split("|")[1].substr(0, 17)+'</a></div>');
xhtml.push('<div class="tjimga"><a href="'+splithtml[i].split("|")[2]+'"><img src="/UploadFiles/2021-04-02/'+splithtml[i].split(">xhtml.push('<div class="otherInfo clearfix"><span>已销售<b>'+splithtml[i].split("|")[4]+'</b>笔</span><a href="'+splithtml[i].split("|")[2]+'">再看看</a></div></div>');
}
xhtml.push('<div class="tr"><a href="javascript:clearcookied();">清空记录</a></div>');
$("#MyHistory").append(xhtml.join(""));
}
else{
var xhtml=new Array();
xhtml.push('<div class="tuijian"><div class="tjname"><a href="'+hc.split("|")[2]+'">'+hc.split("|")[1].substr(0, 17)+'</a></div>');
xhtml.push('<div class="tjimga"><a href="'+hc.split("|")[2]+'"><img src="/UploadFiles/2021-04-02/'+hc.split(">xhtml.push('<div class="otherInfo clearfix"><span>已销售<b>'+hc.split("|")[4]+'</b>笔</span><a href="'+hc.split("|")[2]+'">再看看</a></div></div>');
xhtml.push('<div class="tr"><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>
标签:
浏览历史记录
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“js 实现浏览历史记录示例”评论...