1
<html>
<head><title>test</title>

  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
  </script>
  <!-- ERROR IS HERE the jquery is not being loaded -->

  <script type="text/javascript" src="js/jquery.prettyPhoto.js">
  </script>
  <link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" 
      media="screen" charset="utf-8" />
</head>
<body>
  <a title="Despicable Me" rel="prettyPhoto[movies]" 
    href="http://trailers.apple.com/mymovie.mov?width=640&height=360">
    <img src="images/thumbnails/quicktime-logo.gif" alt="Despicable Me" 
    width="50" />
  </a>
  <a title="Despicable Me" rel="prettyPhoto[movies]" 
    href="ai.mov?width=640&height=360">
    <img src="images/thumbnails/quicktime-logo.gif" 
      alt="Despicable Me" width="50" />
  </a>
  <script type="text/javascript" charset="utf-8">
    $(document).ready(function(){
      $("a[rel^='prettyPhoto']").prettyPhoto();
    });
  </script>
</body>
</html>

当我在 Firefox 中加载此 html 时,错误控制台返回错误:

jQuery is not defined. 

html 文件、js 文件和 css 文件都在同一个文件夹中。我究竟做错了什么?

4

3 回答 3

6

我想你在本地运行这个。(注:不是本地主机,是指你打开了本地的html文件

如果您在本地运行,则//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js意味着file:///ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js

所以你需要指定http://

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

但是,一旦您将页面上传到服务器,就可以使用 just //,这是最佳实践。

于 2012-10-15T11:23:23.320 回答
5

抱歉最后一个答案是错误的

尝试从谷歌下载 jquery 并从本地服务器使用它

<script src="jquery.min.js"></script>

如果所有文件都在同一目录下,那么当您js/在 jquery.prettyPhoto.js 前面附加时,css/ 它们也应该像

<html>
<head>
<title>test</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.prettyPhoto.js"></script>
<link rel="stylesheet" href="prettyPhoto.css" type="text/css" media="screen"  charset="utf-8" />
</head>
<body>
<a title="Despicable Me" rel="prettyPhoto[movies]" href="http://trailers.apple.com/movies/universal/despicableme/despicableme-tlr1_r640s.mov?width=640&height=360"><img     src="quicktime-logo.gif" alt="Despicable Me" width="50" /></a>
<a title="Despicable Me" rel="prettyPhoto[movies]" href="ai.mov?width=640&height=360"><img src="quicktime-logo.gif" alt="Despicable Me" width="50" /> </a>

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
  $("a[rel^='prettyPhoto']").prettyPhoto();
});
</script>
</body>
</html>
于 2012-10-15T11:21:15.530 回答
0

采用

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

从谷歌服务器获取 JQuery 文件

于 2012-10-15T11:22:03.380 回答