2010-04-25 51 views
1

我有問題更新IE中使用.update div的內容;我也嘗試過使用innerHTML而沒有成功。我的腳本適用於firefox和chrome,但我也需要使它適用於IE(7和8均不接受這些功能)。任何提示? 在此先感謝。原型的更新不能與IE工作

上下文是一個簡單的購物車,帶有兩個微調按鈕來修改要購買的物品數量。下面的代碼:

<!-- the input (quantity) --> 
<input type="text" class="cant" id="m__1" value="0" 
    size="2" readonly/> 
<!-- the price associated with the input --> 
<input type="hidden" id="h__1" name="h__1" value="100"/> 
<!-- the "addition" spinner button for the quantity --> 
<input type=button value=" + " onclick="$('m__1').value++;recalc();" 
    style="font-size:11px;margin:0;padding:0;width:20px;height:19px;" > 

<!-- the js function --> 
function recalc() { 

    total = 0 
    $$('input.cant').each(function(field) { 
    var idprice = 'h__' + field.id.substr(3) 
    var price = parseFloat($F(idprice)) 
    var quant = parseInt(field.value) 

    total += (quant * price) 
    }); 
    $('totcart').innerHTML='Total ' + total 
    return total 
} 

<!-- the div --> 
<div align="right" id="totcart"></div> 
+0

任何代碼,說明了什麼? – 2010-04-25 02:01:17

回答

0

沒有足夠的時間去看看現在,改變你的代碼,這使得它雖然工作:

function recalc() { 
    total = 0 
    $$('input.cant').each(function(field) { 
    var idprice = 'h__' + field.id.substr(3) 
    var price = parseFloat($F(idprice)) 
    var quant = parseInt(field.value) 
    total += (quant * price) 
    }); 
    $('totcart').innerHTML='Total ' + total 
    return total 
} 
document.observe("dom:loaded",function(){ 
    $('changer').observe("click",function(){ 
     $('m__1').value++; 
     recalc(); 
    });  
}); 


<!-- the input (quantity) --> 
<input type="text" class="cant" id="m__1" value="0" size="2" readonly/> 
<!-- the price associated with the input --> 
<input type="hidden" id="h__1" name="h__1" value="100"/> 
<!-- the "addition" spinner button for the quantity --> 
<input type=button value=" + " id="changer" style="font-size:11px;margin:0;padding:0;width:20px;height:19px;" > 
<!-- the div --> 
<div align="right" id="totcart"></div> 
+0

我用相應的代碼更新了問題。 – xain 2010-04-25 15:35:29