$().ready(function () { if (typeof (productId) != "undefined") { var productIds_array; if ($.cookie('product_history') == null) { productIds_array = new Array(); productIds_array[0] = productId.toString(); } else { productIds_array = $.cookie('product_history').split(','); } productIds_array.reverse(); var product_history_select = jQuery.inArray(productId.toString(), productIds_array); if (product_history_select >= 0) {//exists productIds_array.splice(product_history_select, 1); //remove } else { if (productIds_array.length == 10) productIds_array.shift(); } productIds_array.push(productId); productIds_array.reverse(); $.cookie('product_history', productIds_array.toString(), { expires: 7, path: '/' }); //设定根目录,可以通过删除会话cookies来重新测试 //example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true }); //alert($.cookie('product_history')); } //load history if ($('#p_history_c').length > 0) { $.post('/ajaxhelper/recentlist.aspx', { ids: $.cookie('product_history') }, function (data) { $('#p_history_c').html(data); $('#p_history_c dd').eq($('#p_history_c dd').length - 1).css('border', 'none'); }); } }); function ClearProductHistory() { $.cookie('product_history', null, {path:'/'}); $('#p_history_c').html(' '); }