您好,欢迎访问一九零五行业门户网

js 实现浏览历史记录示例_javascript技巧

先必须要引用一个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
复制代码 代码如下:
');
xhtml.push('¥'+splithtml[i].split(|)[3]+'
');
xhtml.push('已销售'+splithtml[i].split(|)[4]+'笔再看看
');
}
xhtml.push('清空记录
');
$(#myhistory).append(xhtml.join());
}
else{
var xhtml=new array();
xhtml.push(''+hc.split(|)[1].substr(0, 17)+'
');
xhtml.push('¥'+hc.split(|)[3]+'
');
xhtml.push('已销售'+hc.split(|)[4]+'笔再看看
');
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));});
});
其它类似信息

推荐信息