6

您好,在过去的 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>

萤火虫错误

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

1 回答 1

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>
于 2013-01-26T00:26:24.003 回答