var productPrice =
getFormattedPrice(droppedItem[0].attributes[“price”].nodeValue);
var removeLink = document.createElement(“a”);
removeLink.innerHTML = “Remove”;
removeLink.className = “deleteLink”;
removeLink.href = “#”;
removeLink.onclick = function()
{
$(“.dropZone”).children().remove(“#” + droppedItem[0].id);
updateTotal(productPrice * (-1));
}
droppedItem[0].appendChild(removeLink);
$(this).append(droppedItem);
updateTotal(productPrice);
}
}
);
Accept参数:展示Class= “productItemStyle”的Div
hoverClass参数:当有Product放到DropZone时的样式
drop函数:当Product拖放到DropZone时出发的函数,此函数主要做了一个Product Item的Clone,价格的计算、添加Remove按钮以及到点击Remove按钮时所触发的事件。
价格的计算updateTotal()函数
// update the total!
function updateTotal(price) {
total += parseFloat(price);
$(“#total”).html(total.toFixed(2));
$(“.shoppingCartTotal”).effect(“bounce”);
}
最终效果如下图:

英文原文地址:http://www.codeproject.com/KB/aspnet/JQueryShoppingCart.aspx










