当前位置: 动力学知识库 > 问答 > 编程问答 >

internet explorer - Prototype's update not working with IE

问题描述:

I'm having problems updating a div's content in IE using .update; I also tried with innerHTML with no success. My script works fine with firefox and chrome, but I need to make it work with IE too (neither 7 nor 8 accept the functions). Any hints ?

Thanks in advance.

The context is a simple shopping cart with two spinner buttons to modify the item's quantity to be purchased. Here's the code:

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

网友答案:

not got enough time to look right now, changing your code to this makes it work though:

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>
分享给朋友:
您可能感兴趣的文章:
随机阅读: