我試圖動態計算使用Django/Python和Javascript的訂單總數。動態增加/減少使用單選按鈕的訂單總價格
我正在使用具有預定義值的單選按鈕,這些按鈕是根據哪些產品當前有庫存以及其他項目支持顯示的。
例如:主板,支持RAM的8GB的最大將顯示4單選按鈕,2GB,4GB,6GB和8GB
這是我此輸入字段模板的樣子至今:
{% for ram in orderData.ram %}
<div class="field"><input id="ram{{forloop.counter}}" name="ram" type="radio" class="ram" value="{{ ram.id }}" price="{{ ram.price }}"{% ifequal ram.default 1 %} checked {% endifequal %}/><label>{{ ram.title }}</label> {% ifnotequal ram.price 0 %}<span class="price">add ${{ ram.price }}</span>{% endifnotequal %}</div>
{% endfor %}
我原本打算使用「價格」屬性來存儲價格,但就目前而言,無論何時我選擇不同的單選按鈕,它只會顯示第一個輸入的價格。有沒有辦法解決?我試圖添加一個唯一的ID字段,但它仍然只抓取第一個無線電值..這使得這幾乎是無用的。
的JavaScript/jQuery的:
$("input").change(function(){
var id = $(".ram").attr("id");
alert(id);
alert($("#"+id).attr("price"));
});
我一直在努力試圖找出辦法解決此爲兩小時的大部分時間,我很爲難。任何幫助將非常感激。
**編輯**
總結問題..我怎麼只能獲得當前選定的單選按鈕的價格。
awesome .. thanks a ton – Chris