类型错误$不是函数 [英] Type Error $ is not a function

查看:70
本文介绍了类型错误$不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上使用基于jQuery的记忆游戏。它总体上运作良好,但我希望在最后显示再次播放链接和统计数据。我无法让代码工作。我看到了这个错误:

I am using a jQuery Based Memory Game on my site. It works well overall but I want a "Play Again" Link and stats at the end to show. I cannot get that code to work. I see this error:

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();
    });

这是小提琴

推荐答案

尝试用jQuery()替换$(),看看你是否继续得到这个错误。指示它不是函数的错误意味着jQuery文件尚未加载或者$ name被故意释放。

Try replacing $() with jQuery() and see if you continue to get this error. The error indicating that it isn't a function means that either the jQuery file was not loaded yet or the $ name was freed intentionally.

如果jQuery()函数没有工作,确保您在脚本块/文件之前加载jQuery文件。

If jQuery() function doesn't work, make sure that you are loading the jQuery file before your script block/file.

这篇关于类型错误$不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆