2013-06-18 61 views
0

我有JavaScript的一個具體問題。當我將值打印到控制檯時,它顯示一切正常。但在html中,它顯示了舊的價值,直到我選擇另一個項目,而不是刷新第一個項目。以下是JS和HTML代碼:JS值無法正確顯示

HTML

onmouseover="OrderItem.setTotalPrice(event,this,'{{ menu_item.id }}')" 

JS

setTotalPrice:function(event,a_htmlCaller, a_iMenuItemID){  

    item_total = OrderItem.Topping._order_toppings.find(function(a_oOTopp){ 
      return parseInt(a_oOTopp.iid) == parseInt(a_iMenuItemID);}.bind(this)); 

    var total_price = 0.00; 
    var base_price = parseFloat($('pz-mitem-p-'+a_iMenuItemID).value);   
    var _html = '<div class="tot-price-item"><b>Item Price</b>: '; 

    if(item_total){   
     // go into item details but with no changes  
     if(item_total.toppings.tot_price.length == 1 && item_total.toppings.tot_price[0].length == 0){          
      total_price += base_price; 
      _html += '' + total_price;  
     }else{       
      for(var i=0; i < item_total.toppings.tot_price.length; i++){ 

      // total_price += parseFloat(item_total.toppings.tot_price[i][0]); 
       _html += '<div>' + (parseFloat(item_total.toppings.tot_price[i][0]).toFixed(2)).toString() + '</div>';   


      }    
     }  

    }else{   
     total_price += base_price; 
     _html += '' + total_price; 
    } 
    _html += '</div>';  



    Tips.add(
     a_htmlCaller, 
     event,        
     _html, 
     { 
      className:'rounded', 
      stem: true, 
      tipJoint: [ 'left', 'middle' ], 
      target:a_htmlCaller,  
      targetJoint: null//[ 'right', 'right' ] 
     } 
    );   

},  

編輯:在評論提問者給出添加的代碼。新增格式。

提示:如果不張貼在註釋代碼,它張貼在你原來的問題編輯,因爲它使你更容易完全沒有格式閱讀,而不是一個巨大的爛攤子評論。

for(var i=0; i < item_total.toppings.tot_price.length; i++) { 
    //total_price += parseFloat(item_total.toppings.tot_price[i][0]); 
    _html += '<div>' + (parseFloat(item_total.toppings.tot_price[i][0]).toFixed(2)).toString() + '</div>'; 
    test = parseFloat(item_total.toppings.tot_price[i][0]).toFixed(2); 
    console.log(test); 
} 
+1

你能告訴我們其餘的代碼嗎?或者更好,做一個小提琴。 –

+0

這裏的console.log在哪裏?我看不到它。他們是否在不同的地方? – casraf

+0

「爲(VAR I = 0; I '; \t \t \t \t \t \t \t \t \t \t \t測試= parseFloat(item_total.toppings.tot_price [I] [0])toFixed(2)。 \t \t \t \t \t的console.log(測試); \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t}」 – Fi3n1k

回答

0

它不允許我添加評論,所以我不得不在這裏發帖。

不管怎麼說,我建議你看一看this

祝你好運!

(我需要更多的代碼才能得到確切的答案)