javascript – jQuery TypeError:$(“img”).draggable();不是函数

前端之家收集整理的这篇文章主要介绍了javascript – jQuery TypeError:$(“img”).draggable();不是函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
您好,我在过去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>

解决方法

你没有加载jquery,只有jquery-ui. jquery本身不是由jquery-ui加载的,所以你需要2个不同的脚本标签.
<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>
原文链接:https://www.f2er.com/jquery/153991.html

猜你在找的jQuery相关文章