Javascript错误:jQuery未定义

[英]Javascript error: jQuery is not defined


<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>

When I load this html in firefox, the error console returns an error:

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

jQuery is not defined. 

The html file, js file, and the css file are all in the same folder. What am I doing wrong?

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

3 个解决方案

#1


6  

I think you run this in local. (Note: not mean localhost, mean you opened the local html file)

我想你是在本地运行的。 (注意:不是指localhost,意思是你打开了本地的html文件)

If you run in local, then //ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js means file:///ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js

如果您在本地运行,则//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

So you need to specify the http://

所以你需要指定http://

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

But once you upload your page to the server, it's ok with just //, and this is best practice.

但是一旦你将页面上传到服务器,只需//就可以了,这是最好的做法。

#2


5  

Sorry Last Answer was wrong

抱歉,上次回答错了

Try downloading jquery from google and use it from local server like

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

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

AND

If all files are under same directory then when you are appending js/ in front of jquery.prettyPhoto.js and also css/ they should be like

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

<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>

#3


0  

use

使用

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

to get the JQuery file from the google server

从谷歌服务器获取JQuery文件


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/10/15/4726c080037c90661ec926c0e20f3edb.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com