2
我在我的網站上使用了jQuery Based Memory Game。您可以隨時重新啓動遊戲。很棒。現在我完成了一場比賽,然後我再次擊球。如果我重新啓動它不再有效。爲什麼和如何解決它?重新啓動遊戲jQuery功能不起作用
這是fiddle。
JS:
// this script shows how you can get info about the game
var game = jQuery('div.slashc-memory-game'); // get the game
var info = jQuery('p#info').find('span'); // get the info box
var restart = jQuery('a#restart').css('visibility', 'visible'); // get the play again link
var playAgain = jQuery('a#play-again').css('visibility', 'hidden'); // get the play again link
// format time like hh:mm:ss
var formatTime = function(s)
{
var h = parseInt(s/3600), m = parseInt((s - h * 3600)/60); s = s % 60;
return (h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s);
}
// listen for game 'done' event
game.bind('done', function(e)
{
// show basic stats
var stats = game.slashcMemoryGame('getStats');
info.html('Success ! Number of clicks : ' + stats.numClicks + ', elapsed time : ' + formatTime(parseInt(stats.time/1000)) + '.');
playAgain.css('visibility', 'visible'); // show link
restart.css('visibility', 'hidden'); // show link
});
// Restart action
restart.click(function(e)
{
game.slashcMemoryGame('restart'); // restart game
});
// play again action
playAgain.click(function(e)
{
playAgain.css('visibility', 'hidden'); // hide link
info.html('Memory Game, click to reveal images. <a id="restart" href="#">Restart</a>'); // reset text
game.slashcMemoryGame('restart'); // restart game
e.preventDefault();
});
HTML:
<p id="info"><span>Memory Game, click to reveal images. <a id="restart" href="#">Restart</a></span> <a id="play-again" href="#">Play Again</a></p>
這是我後功能body' – Peter
我跑你的小提琴(corretcting相同的問題在你前面的問題,取消比賽var和移除結束script標籤後)得到的螢火控制檯'失蹤},它仍然能正常工作。我可以玩這個遊戲,並且在我完成遊戲後,我可以再次玩這個遊戲。我再次擊球后,比賽繼續工作。所有似乎對我來說工作得很好(Chrome on Win)http://jsfiddle.net/ZXMUB/7/ – Pevara
@PeterVR - 我給了錯誤的小提琴鏈接,我的壞(新鏈接問題)。在您再次點擊Play後遊戲重置,然後您點擊重新啓動遊戲不重新啓動。注意:在第一次完成之前重新啓動。 – L84