先必须要引用一个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"> <BR>//读取cookied历史记录 <BR>$(function(){ <br><br>var hc=$.cookie("history"); <BR>if(hc!=null) <BR>{ <BR>if(hc.indexOf("*")!=-1) <BR>{ <BR>var splithtml=hc.split("*"); <BR>var xhtml=new Array(); <BR>var hlength=splithtml.length; <BR>if(parseInt(hlength)>4) <BR>hlength=4; <BR>for(var i=0;i<parseInt(hlength);i++) <BR>{ <BR>xhtml.push('<div class="tuijian"><div class="tjname"><a href="'+splithtml[i].split("|")[2]+'">'+splithtml[i].split("|")[1].substr(0, 17)+'</script>
');
xhtml.push('
');
xhtml.push('
');
}
xhtml.push('
');
$("#MyHistory").append(xhtml.join(""));
}
else{
var xhtml=new Array();
xhtml.push('
');
xhtml.push('
');
$("#MyHistory").append(xhtml.join(""));
}
}
else
{
$("#MyHistory").append("
");
}
});
function clearcookied()
{
$.cookie('history',null,{expires:1,domain:'.nrqiang.com'});
$("#MyHistory").html("
");
}
$(function() {
$("img").each(function(){$(this).attr("src",$(this).attr("original"));});
});
Java免费学习笔记:立即使用
解锁 Java 大师之旅:从入门到精通的终极指南











