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只在第一个随机数集上刷新。
答案 0 :(得分:2)
使用setTimeout
代替setInterval
。
function scheduleNextLoad() {
setTimeout(function () {
$('#screen').load('screen.php');
scheduleNextLoad();
}, Math.floor(Math.random() * 10000));
}
scheduleNextLoad();