简体   繁体   English

Javascript函数结果不会在firefox中显示

[英]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. 我发现了一个javascript函数,它增加了一个值,然后它显示在一个html div中。 It works perfectly in every browser except Firefox, and I'm really struggling to get a reason why. 除了Firefox之外,它在每个浏览器中都能完美运行,我真的很难找到原因。

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. 请改用amount.innerHTML

See this post 'innerText' works in IE, but not in Firefox for the reason why amount.innerText does not work in Firefox. 看到这篇文章'innerText'在IE中工作,但在Firefox中没有,因为amount.innerText在Firefox中不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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