我在我的网站上使用了jQuery Based Memory Game。它的整体效果很好,但我想要一个“再次播放”链接并在最后显示统计数据。我无法获得该代码的工作。我看到这个错误:
TypeError: $ is not a function
[Break On This Error]
var game = $('div.slashc-memory-game'); // get the game
这里是JS:
// this script shows how you can get info about the game
var game = $('div.slashc-memory-game'); // get the game
var info = $('p#info').find('span'); // get the info box
var playAgain = $('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
});
// play again action
playAgain.click(function(e)
{
playAgain.css('visibility', 'hidden'); // hide link
info.html('Memory Game, click to reveal images'); // reset text
game.slashcMemoryGame('restart'); // restart game
e.preventDefault();
});
这里是一个Fiddle
'语法错误:缺少}函数体'后 –
设置一个不模仿实际问题的小提琴没有多大意义。 – Pointy
您的网站适合我。然而,小提琴充满了复制和粘贴错误 – Eric