让jQuery工作的问题

时间:2014-09-27 19:14:54

标签: javascript jquery

我是jQuery的新手,似乎无法让它在我的计算机本地工作。我已将生产jQuery 2.1.1中的代码保存为jquery.min.js。但是当我尝试在项目中使用jquery时它不起作用。如果我单击我保存的jquery.min.js文件,它会放弃Microsoft脚本错误"'默认视图'是null或不是对象"。我一直在使用这段代码来查看是否安装了jQuery。任何想法?

<!doctype html>
<html>
  <head>
    <title>Learning jQuery</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src="jquery.min.js"></script>
  </head>

  <body>
    <script>
      if (typeof jQuery != "undefined") {
         alert('jQuery is installed!');
    </script>
  </body>
</html>

3 个答案:

答案 0 :(得分:0)

您缺少IF语句的结束大括号。

<!doctype html>
<html>
  <head>
    <title>Learning jQuery</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src="jquery.min.js"></script>
  </head>

  <body>
    <script>
      if (typeof jQuery != "undefined") {
         alert('jQuery is installed!');
      }                                  //  <---- Right here!
    </script>
  </body>
</html>

答案 1 :(得分:0)

尝试使用CDN中的jQuery来检查问题[来源:http://jquery.com/download/]

<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>

包含它的其他方式如下:http://www.w3schools.com/jquery/jquery_install.asp

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

此外,代码

中缺少结束括号
<!doctype html>
<html>
  <head>
    <title>Learning jQuery</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src="jquery.min.js"></script>
  </head>

  <body>
    <script>
      if (typeof jQuery != "undefined") {
         alert('jQuery is installed!');
       }//** <--------here is the missing closing braces **

    </script>
  </body>
</html>

答案 2 :(得分:0)

我已为您的代码制作了一些内容,请检查

1.关闭了大括号。

2.更改了min文件。

我认为主要的错误在于语法,因为你还没有关闭if条件的大括号。

<!doctype html>
<html>
  <head>
    <title>Learning jQuery</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
   
  </head>

  <body>
     <script>
      if (typeof jQuery != "undefined") {
         alert('jQuery is installed!');
      }
    </script>
  </body>
</html>

相关问题