繁体   English   中英

ReferenceError:找不到变量:$

[英]ReferenceError: Can't find variable: $

大家好,我在chrome上运行游戏时,它可以正常工作,但是当我在模拟器上尝试该游戏时,我的JavaScript代码出现错误,我无法理解来源或原因

这是错误:

05-13 11:53:11.726: E/Web Console(790): ReferenceError: Can't find variable: $ at file:///android_asset/www/js/html5games.matchgame6.js:5

错误在第5行:这是我的javascript文件内容:

  var matchingGame = {};
  ***var uiPlay1 = $("#gamePlay1");***  //////line 5
  var uiPlay2 = $("#gamePlay2");
  var uiIntro = $("#popup");
  var uiExit = $("#gameExit");
  var uiNextLevel = $("#gameNextLevel");
  var uigameQuit =$("#gameQuit");
 var uiPlay3 = $("#gamePlay3");
 matchingGame.savingObject = {};

 matchingGame.savingObject.deck = [];

 matchingGame.savingObject.removedCards = [];

 // store the counting elapsed time.
  matchingGame.savingObject.currentElapsedTime = 0;

  //store the last-elapsed-time

//matchingGame.savingObject.LastElapsedTime = 0;//now


  // store the player name
  matchingGame.savingObject.palyerName=$("#player-name").html();
  matchingGame.savingObject.currentLevel="game6.html";
  // all possible values for each card in deck
matchingGame.deck = [
'cardAK', 'cardAK',
'cardAQ', 'cardAQ',
'cardAJ', 'cardAJ',

  ];

   $(  function(){init();}  );


  //initialise game
   function init() {


                    $("#game").addClass("hide");

                    $("#cards").addClass("hide");


                   uiPlay1.click(function(e) {
                    e.preventDefault();

            $("#popup").addClass("hide");
            startNewGame();


             });

                uiPlay2.click(function(e) {
                    e.preventDefault();
                $("#popup").addClass("hide");
                        var savedObject = savedSavingObject();
               // location.href =savedObject.currentLevel ;

                if (savedObject.currentLevel=="game6.html")
                 rejouer();
                 else 
                 location.href =savedObject.currentLevel ;

                //ResumeLastGame();
                //alert ("level :"+savedObject.currentLevel );

                });

            uiExit.click(function(e) {e.preventDefault();
                                     //alert("u clicked me ");
                                    }
                        );



                uiPlay3.click(function(e) {
                e.preventDefault();
                $("#popupHelp").fadeIn(500, function() {
                $(this).delay(10000).fadeOut(500)}); });


    }

任何想法请先谢谢你

您可能没有包括jQuery。

大概您没有在任何地方定义$函数。

也许您是从文档工作开始的,假设您已经加载了Prototype.jsMootoolsjQuery或设置了该名称(非常糟糕)的变量的许多其他库之一。

在使用$之前,请确保已加载jquery,mootools,其他javascript库等。

您是否在文档末尾包含了库,并且在下载库之前编写了脚本。

确保您有一个引用库的脚本标签,然后包含脚本内容。

另外要注意的一件事是,在执行脚本时,可能未加载文档,并且页面上可能不存在某些控件,因此请确保将它们包装在API中,该API将在文档运行后运行该函数。完全加载。 在jquery中,您使用$(document).ready(function(){});

我正在Ejecta中开发一个JS应用程序。 包含了jQuery,但DOM准备就绪不适用于Ejecta。 相反,在网站/应用程序初始化上,我这样做:

function func() {
    init();
    animate();
}

setTimeout(func, 1000);

这使jQuery有时间进行加载和解析。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM