0
我用下面的代碼試圖Javascript代碼凍結屏幕時
- 顯示卡片遊戲的結果設定量,而顯示
- 等待3秒的倒數,然後,
重新加載屏幕。
//Display results, at least that was the idea. for(var player = 0; player < players.length; player++) { resultString = players[player][6] if (result == null) { resultString += ", its a tie."; } else { resultString += (player == 0 ? ", you" : ", cassino") + (player == result ? (player == 0 ? " win" : " wins") : (player == 0 ? " lose" : " loses")); document.getElementById(player == 0 ? "player" : "casino"). childNodes[0].nodeValue = resultString; } showHand(players[player]); } //Lag for 3 seconds while displaying a countdown. At least it lags alright. var time = new Date().getTime(); while (((time/1000) + 3) - (new Date().getTime()/1000) > 0) { document.getElementById("call").childNodes[0].nodeValue = "Next round in " + Math.ceil(((time/1000) + 3) - (new Date().getTime()/1000)) .toFixed(0); } //Reload screen. Working fine. dealHands(); }
的問題是,通過運行該代碼的屏幕而不是凍結用於加載重新加載屏幕,即使在被顯示的console.log指出的價值觀沒有問題之前3秒程序的「//顯示結果」部分。實際上,如果我在評論「//滯後3秒...」之後評論部分,結果將按預期顯示。 有沒有.time()的某些屬性,我不知道這是重寫代碼?