2012-10-15 62 views
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中,错误控制台会返回一个错误:JavaScript错误:jQuery是没有定义

jQuery is not defined. 

的HTML文件,js文件,以及CSS文件都在同一文件夹。我究竟做错了什么?

+0

究竟是什么src =“// ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js”路径 –

+2

检查chrome中的网络标签以查看jquery是否正在下载正确 –

+0

jquery路径是错误的。没什么严肃的,寒意 – defau1t

回答

6

得到JQuery的文件,我想你在本地运行此。 (注:不是指本地主机,意味着你打开本地的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> 

但一旦你把你的页面上传到服务器上,没关系,只需要//,这是最好的做法。

+0

@upvoter,因为它的本地主机也 –

+0

@智慧我不是指本地主机,我的意思是你运行的HTML本地文件。 – xdazz

+0

@xdazz我的歉意,以为你只是建议像其他人一样加入'http:'。在你编辑之后,我看到你在说什么,在web服务器之外访问它将使用'file:'协议,它不适合读取脚本。 – GenericJon

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

使用

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

从谷歌服务器

相关问题