Javascript到jQuery的转换需要

时间:2012-03-23 10:36:52

标签: javascript jquery

不确定100%以下的代码是否正确,但它正在完成工作,现在需要转换为jQuery。

var count = 0.00;
var currency = "R$";

function doCount() {
    count = count + 1.99;
    document.getElementById("number").innerHTML = currency + parseFloat(count).toFixed(2).replace(/\./g, ',');
    var tim = setTimeout('doCount()', 60000); // increment every 60 seconds
}
doCount();

3 个答案:

答案 0 :(得分:5)

jQuery不是一种语言,它只是一个让你的javascript写得更简单的库。如果它像这样工作,则无需将其转换为jQuery。

答案 1 :(得分:3)

var count = 0.00; 
var currency = "R$";

function doCount() { 
  count = count + 1.99; 
  $("#number").html(
    currency + parseFloat(count).toFixed(2).replace(/./g, ',')
  ); 
  var tim = setTimeout('doCount()', 60000); // increment every 60 seconds 
} 
doCount();

答案 2 :(得分:0)

使用setInterval

var count = 0.00,
    currency = "R$";

setInterval(function { 
    count = count + 1.99; 
    $("#number").html(
        currency + parseFloat(count).toFixed(2).replace(/./g, ',')
    ); 
}, 60*1000); // increment every 60 seconds 

感谢@deadrunk