<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>
Run Code Online (Sandbox Code Playgroud)
当我在firefox中加载此html时,错误控制台会返回错误:
jQuery is not defined.
Run Code Online (Sandbox Code Playgroud)
html文件,js文件和css文件都在同一个文件夹中.我究竟做错了什么?
我想你是在本地运行的.(注意:不是指localhost,意思是你打开了本地的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>
Run Code Online (Sandbox Code Playgroud)
但是一旦你将页面上传到服务器,它就可以了//,这是最好的做法.
抱歉,上次回答错了
尝试从谷歌下载jquery并从本地服务器使用它
<script src="jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
和
如果所有文件都在同一目录下,那么当你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>
Run Code Online (Sandbox Code Playgroud)