您好,我在过去3个小时内遇到过此代码的问题,我希望有人可以帮助我。
的jQuery
$(document).ready(function() {
$("img").draggable();});
HTML标题
<head>
<title>Chess</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<link rel="stylesheet" type="text/css" href="reset.css" />
<link rel="stylesheet" type="text/css" href="default.css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="default.js"></script>
</head>
FireBug错误
TypeError: $("img").draggable is not a function [Break On This Error] $("img").draggable();
我的代码在codecademy.com上完美运行但是当我在localhost或我的服务器上尝试时,我不断收到此错误消息。我在这里做错了什么?
完整HTML
<!DOCTYPE html>
<html>
<head>
<title>Chess</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<link rel="stylesheet" type="text/css" href="reset.css" />
<link rel="stylesheet" type="text/css" href="default.css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="default.js"></script>
</head>
<body>
<div id="board">
<ul id="first_row">
<li class="white_space"><img src="pieces/Rook_Black.png" /></li>
<li class="black_space"><img src="pieces/Pawn_Black.png" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="pieces/Pawn_White.png" /></li>
<li class="black_space"><img src="pieces/Rook_White.png" /></li>
</ul>
<ul id="second_row">
<li class="black_space"><img src="pieces/Knight_Black.png" /></li>
<li class="white_space"><img src="pieces/Pawn_Black.png" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="pieces/Pawn_White.png" /></li>
<li class="white_space"><img src="pieces/Knight_White.png" /></li>
</ul>
<ul id="third_row">
<li class="white_space"><img src="pieces/Bishop_Black.png" /></li>
<li class="black_space"><img src="pieces/Pawn_Black.png" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="pieces/Pawn_White.png" /></li>
<li class="black_space"><img src="pieces/Bishop_White.png" /></li>
</ul>
<ul id="forth_row">
<li class="black_space"><img src="pieces/Queen_Black.png" /></li>
<li class="white_space"><img src="pieces/Pawn_Black.png" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="pieces/Pawn_White.png" /></li>
<li class="white_space"><img src="pieces/King_White.png" /></li>
</ul>
<ul id="fifth_row">
<li class="white_space"><img src="pieces/King_Black.png" /></li>
<li class="black_space"><img src="pieces/Pawn_Black.png" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="pieces/Pawn_White.png" /></li>
<li class="black_space"><img src="pieces/Queen_White.png" /></li>
</ul>
<ul id="sixth_row">
<li class="black_space"><img src="pieces/Bishop_Black.png" /></li>
<li class="white_space"><img src="pieces/Pawn_Black.png" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="pieces/Pawn_White.png" /></li>
<li class="white_space"><img src="pieces/Bishop_White.png" /></li>
</ul>
<ul id="seventh_row">
<li class="white_space"><img src="pieces/Knight_Black.png" /></li>
<li class="black_space"><img src="pieces/Pawn_Black.png" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="pieces/Pawn_White.png" /></li>
<li class="black_space"><img src="pieces/Knight_White.png" /></li>
</ul>
<ul id="eight_row">
<li class="black_space"><img src="pieces/Rook_Black.png" /></li>
<li class="white_space"><img src="pieces/Pawn_Black.png" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="#" /></li>
<li class="white_space"><img src="#" /></li>
<li class="black_space"><img src="pieces/Pawn_White.png" /></li>
<li class="white_space"><img src="pieces/Rook_White.png" /></li>
</ul>
</div>
</body>
</html>
答案 0 :(得分:13)
你没有加载jquery,只有jquery-ui。 jquery本身不是由jquery-ui加载的,所以你需要2个不同的script
标签。
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>