我想将选定的ID(使用Guids)存储到以后用于结帐的Cookie中。如何将新值存储到cookie中而不会覆盖旧值?
<script type="text/javascript">
$(document).ready(function () {
$('.AddProduct').click(function () {
//add following: $(this).data('id'), this is how far I got:
//$.cookie("AddedProductId", $(this).data('id'));
});
});
</script>
$(this).data('id')
从foreach循环中获取产品的ID:
<button class="AddProduct" data-ID="@item.ID">Add to Cart</button>
答案 0 :(得分:0)
只需阅读您的Cookie,然后使用新值附加
<script type="text/javascript">
$(document).ready(function () {
$('.AddProduct').click(function () {
//add following: $(this).data('id'), this is how far I got:
var previousValues = $.cookie("AddedProductId", $(this).data('id'));
$.cookie("AddedProductId", previousValues+' ' + $(this).data('id'));
});
});