我在我的網站上有一個購物車,我需要讓用戶輕鬆地更改他們在購物車中的物品數量。使用jQuery和一些輸入創建一個鍵/對象
下面是javascript代碼我到目前爲止:
<script type="text/javascript" language="javascript">
$(document).ready(function() {
var items = [];
$(".item").each(function() {
var productKey = $(this).find("input[type='hidden']").val();
var productQuantity = $(this).find("input[type='text']").val();
items.addKey(productKey, productQuantity); ?
});
// 1. Grab the values of each ammount input and it's productId.
// 2. Send this dictionary of key pairs to a JSON action method.
// 3. If results are OK, reload this page.
});
</script>
我寫的評論是我對如何進行公正的準則。
有沒有辦法將一個鍵/對元素添加到一個排序數組?我只需要它有一個關鍵和價值。沒有什麼花哨。
我寫了一個addKey()
方法只是爲了說明的目的,以顯示我想完成。