javascript jQuery .sortable 不是一个函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16694056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 05:39:29  来源:igfitidea点击:

jQuery .sortable is not a function

javascriptjquery-ui

提问by Robyn Paxton

Even though I've followed the directions in the jQuery UI documentation, I'm getting the error that .sortable is not a function.
Here is my code:

尽管我已按照 jQuery UI 文档中的说明进行操作,但我还是收到了 .sortable 不是函数的错误消息。
这是我的代码:

<div style="float: left;">
    <span class="caption" style="width: 255px; display: block;">
        Assigned Limits
    </span>
    <div class="assigned-limit-box">
        <ul id="limAssigned" class="ul-base">
        </ul>
    </div>
</div>

This is my js:

这是我的js:

$('#limAssigned').sortable();

My jQuery js is loaded before my jQuery UI js.

我的 jQuery js 在我的 jQuery UI js 之前加载。

What am I doing wrong?

我究竟做错了什么?

采纳答案by Robyn Paxton

I figured it out. The page that I needed sortable for is loaded into a div within my main page. I had to add the jQuery UI script to that jsp rather than the main page jsp. Funny how that worked out.

我想到了。我需要对其进行排序的页面被加载到我的主页中的一个 div 中。我必须将 jQuery UI 脚本添加到该 jsp 而不是主页 jsp。有趣的是这是如何解决的。

回答by user3279807

I had the same issue when a page using the sortable() function was required by a main php page. Adding the following code within the head of the main page wasn't sufficient. Adding it also at the beginning of the required page (inside the body in my case) fixed everything.

当主 php 页面需要使用 sortable() 函数的页面时,我遇到了同样的问题。在主页的头部添加以下代码是不够的。将它添加到所需页面的开头(在我的例子中是在正文中)修复了所有内容。

<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

回答by Gabe

I got this error by having more than 1 version of jQuery on the page. Credit goes to IonicBurger: jQuery sortable is not a function

由于页面上有超过 1 个版本的 jQuery,我收到了此错误。归功于 IonicBurger:jQuery sortable 不是一个函数

回答by Mohammad.Trabelsi

jQuery UI and jQuery must be loaded in a certain order:

jQuery UI 和 jQuery 必须按特定顺序加载:

<script src="jquery.js">...
<script src="jquery-ui.js">...

Make sure you are including jQuery UI after jQuery.

确保在 jQuery 之后包含 jQuery UI。

回答by Mohammad.Trabelsi

it worked for me with this specific version of Jquery

这个特定版本的 Jquery 对我有用

    <script src="//code.jquery.com/jquery-1.12.4.js"></script>

but it doesn't work for newer versions

但它不适用于较新的版本