我试图在JavaScript中编写自己的幻灯片。我已经是在Opera,Safari和Chrome浏览器的一个骨架:JavaScript中奇怪的算术行为
var slideShow = (function() {
var latestGames = document.getElementById('latestGames').getElementsByTagName('li');
var displayedGame = 0;
return {
init: function() {
latestGames[displayedGame].style.display = 'inline';
setInterval(this.update, 3000);
},
update: function(gameToDisplay) {
console.log("Displayed game: " + displayedGame);
latestGames[displayedGame].style.display = 'none';
gameToDisplay = gameToDisplay || (displayedGame === (latestGames.length - 1) ? 0 : ++displayedGame);
console.log("Game to display: " + gameToDisplay);
console.log('====================');
latestGames[gameToDisplay].style.display = 'inline';
displayedGame = (gameToDisplay == latestGames.length ? 0 : gameToDisplay);
}
}
})();
,但在Firefox当我登录了gameToDisplay可变我只得到随机数。我看不出错误在哪里。
预先感谢。
你是如何初始化'gameToDisplay'的? –
是一个可选参数。如果它未定义,我用0初始化它(第12行)。 – Tae
您的问题标题对您所面临的问题没有描述性,而且我不太清楚在阅读问题后实际存在的问题。你可以http://jsfiddle.net一个工作演示? –