Prototype的更新不适用于IE

时间:2010-04-25 01:31:29

标签: internet-explorer prototypejs

我在使用.update更新IE中div的内容时遇到问题;我也试过使用innerHTML但没有成功。我的脚本适用于firefox和chrome,但我也需要使用IE(7和8都不接受这些功能)。任何提示? 提前谢谢。

上下文是一个简单的购物车,带有两个微调按钮,用于修改要购买的商品数量。这是代码:

<!-- 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>

1 个答案:

答案 0 :(得分: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>
相关问题