商店。車輸入單選按鈕更改算法
name | price | count | price*count
apple 2 2 4
banana 3 4 12
Delivery
(radio button) none | checked
(radio button) to home (+3)
(radio button) to another town (+6)
Total Count | 16
- 當您更改計數 - 我的腳本動態回憶總數和變化與jQuery總數文本()
現在我只需要當交貨的變化來動態改變總數的文本。
我只是沒有得到如何。
如果我將其更改爲to home
,總計數+ = 3,那麼如果我改變count
的項目,總計數+ =((價格* newcount)正價*計)
但當我改變發送到another town
,總計數= =(新的輸入 - prev.input無線電),但當我改回0,總計數=(輸入值)
我的JQuery腳本簡單地改變取值price*count
, price
和count
兄弟姐妹值和檢查 - 如果不同,則更改總計數文本。
var updating = false;
if(!updating){
updatePrice();
}
function updatePrice(){
var pricewas = pricecountitem.text();
var pricenow = pricecount;
var difference = pricenow - pricewas;
var numadd = 1;
if(difference < 0){
pricecountitem.text(+pricewas - numadd);
}else if(difference > 0) {
pricecountitem.text(+pricewas + numadd);
}
if(difference !== 0){
updating = true;
setTimeout(updatePrice, 1000);
}else{
updating = false;
}
}
我只是不能寫algoritm如何動態地改變包括交付的所有情況下的價值和數量的變化。
我的頭會爆炸,你們可以幫我嗎?
你爲什麼試圖計算差異?你不能只是簡單地重新計算整個價格並改變它嗎?只要您顯示正確的價值,價格是否發生了變化是否重要?您也可以存儲小計(無需交付),只需重新計算變更總計(小計+交貨)即可。 – benzonico 2013-02-24 13:15:41