0
var randomNumber = Math.floor(Math.random() * 10000);
// Sets the variable randomNumber to a random number between 0 and 1 x 10,000

var auto_refresh = setInterval(function() {
    $('#screen').load('screen.php');
}, (randomNumber));
// Refreshes #screen at an interval of randomNumber

我希望每次#screen div 刷新时,都会生成一个新的随机数。就像现在一样,div 仅在第一个随机数集时刷新。

4

1 回答 1

2

使用setTimeout而不是setInterval.

function scheduleNextLoad() {
    setTimeout(function () {
        $('#screen').load('screen.php');
        scheduleNextLoad();
    }, Math.floor(Math.random() * 10000));
}

scheduleNextLoad();
于 2013-05-27T03:27:15.477 回答