我是jQuery的初学者。以下代码在页面加载时返回“ number ”的值。我希望自动递增数字2秒并更新值,并且应该在页面中可用。我怎么能这样做?
$(document).ready(function() {
$('.one').myNumber({
number: 12555456
});
});
答案 0 :(得分:4)
jQuery(function(){
setInterval(function(){ //Calls a function every X ms as specified in param 2
var _nbr = parseInt(jQuery('.one').text());//Get number from element as int
jQuery('.one').text(++_nbr);//Increment variable and puts it in the element
},2000);//Number of ms between function calls
});
查找那些: .parseInt() .setInterval() .text()