我是jQuery的新手,并且使用更简单的脚本创建了一个简单的index.html。但是,jQuery库似乎没有在我的firebug控制台中加载,我收到以下错误:
TypeError: $ is not a function
$(document).ready(function() {
以下是我的index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Online Calorie Tracker and Analyzer</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script src="http//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="initialize.js"></script>
</head>
<body>
<div class="container">
<h1>Calorie Tracker and Analyzer</h1>
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="#">Track Food</a></li>
<li><a href="#">Analyze Food</a></li>
</ul>
</div>
</div>
</div>
<div class="hero-unit">
<h1>A healthy you begins with tracking and analysis</h1>
<p>10 out of 10 doctors agree. Losing weight is healthy. With our online calorie tracker and analyzer, the power is in your hands!</p>
<button class="btn btn-danger" id="btn1">Get Started</button>
</div>
</div>
<body>
<html>
这是jQuery脚本:
$(document).ready(function() {
alert("hello");
});
感谢任何帮助!
答案 0 :(得分:5)
<script src="http//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
应该是:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
此外,建议在<body>
标记结束之前加载JavaScripts,以提高页面加载速度。
此外:
您的结束<body>
标记应为</body>
(缺少正斜杠)。
答案 1 :(得分:0)
我遇到了同样的问题,也是因为互联网问题。有时由于超时cdn无法加载库。在这种情况下,请尝试下载库并在项目中使用它:http://jquery.com/download/。