简体   繁体   中英

Javascript function result doesn't show in firefox

I found a javascript function that increments a value and then it's showed in a html div. It works perfectly in every browser except Firefox, and I'm really struggling to get a reason why.

The code looks like this:

<script type="text/javascript">

$(window).load(function(){
var amount = document.getElementById('amount');
var start = new Date("March 12, 2014 12:28:00").getTime();
var current;
update();

function update() {
    var current = (new Date().getTime() - start)/1000*1.00+0;
    amount.innerText = formatMoney(current);
}

setInterval(update,1000);

function formatMoney(amount) {
    var dollars = Math.floor(amount).toString().split('');
    var cents = (Math.round((amount%1)*100)/100).toString().split(',')[1];
    if(typeof cents == 'undefined'){
        cents = '00';
    }else if(cents.length == 1){
        cents = cents + '0';
    }
   var str = '';
    for(i=dollars.length-1; i>=0; i--){
        str += dollars.splice(0,1);
        if(i%3 == 0 && i != 0) str += '.';
    }
    return str + ' ' + '€';
}
});


</script>

<div id='amount'></div>

Use amount.innerHTML instead.

See this post 'innerText' works in IE, but not in Firefox for the reason why amount.innerText does not work in Firefox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM