jQuery 可排序不是一个函数
我正在尝试使用 Sortable jQuery UI 插件版本 1.8.16 制作可单击并拖动的有序项目列表。但是,我不断收到 $("#ol-id ol").sortable 不是函数
的错误,其中 'ol-id' 是列表的 id。我的代码如下:
//Sorting stuff
if($("#li-id li").size()>1) {
$("#ol-id ol").sortable({
revert: true,
axis: 'y',
containment: 'parent',
cursor: 'move',
handle: 'div.link_div',
smooth: false,
opacity: 0.7,
tolerance: 'pointer',
start: function(){
$("#ol-id").removeClass("bottom_dragged");
},
update: function(){
$("#ol-id ol").sortable({disabled : true});
$("#saving_indicator").html("saving...")
$("#saving_indicator").show();
//do other stuff...
}
})
}
奇怪的是,错误在 Firebug 中显示为与 update: function(){
在线。
我已经验证在加载页面和加载 jQuery UI 库后会调用此函数。我在标头中包含 jquery-1.6.2.min.js 和 jquery-ui-1.8.16.custom.min.js 。此外,我已验证所有 ID 名称均正确且与其 HTML 对应项相匹配。
那么,如果不是缺少与资源相关的东西,那么是什么导致了问题呢?
编辑:这是我的 HTML 标头:
<link href="/_css/styles.css?mod=1317745564" type="text/css" rel="stylesheet">
<link href="/_javascript/qtip/jquery.qtip.min.css?mod=1315947301" type="text/css" rel="stylesheet">
<script type="text/javascript" async="" src="http://www.google-analytics.com/ga.js">
<script type="text/javascript" async="" src="http://www.google-analytics.com/ga.js">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
<link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/start/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/le-frog/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js" type="text/javascript">
<script src="/_javascript/sets.js?mod=1320080042" type="text/javascript"> //Sorting stuff code is here
<script type="text/javascript" src="http://dev.selfcheck.vudat.msu.edu/_javascript/jquery.jsonp.js">
<script type="text/javascript" src="http://dev.selfcheck.vudat.msu.edu/_javascript/jquery.form.js">
<script type="text/javascript" src="http://dev.selfcheck.vudat.msu.edu/_javascript/qtip/jquery.qtip.min.js">
<link href="/_css/ui/ui.core.css?mod=1315947279" type="text/css" rel="stylesheet">
<link href="/_css/ui/ui.theme.css?mod=1315947280" type="text/css" rel="stylesheet">
I am trying to make an ordered list of items click-and-draggable with the Sortable jQuery UI plugin version 1.8.16. However, I keep getting the error that $("#ol-id ol").sortable is not a function
, with 'ol-id' being the id of the list. My code is as follows:
//Sorting stuff
if($("#li-id li").size()>1) {
$("#ol-id ol").sortable({
revert: true,
axis: 'y',
containment: 'parent',
cursor: 'move',
handle: 'div.link_div',
smooth: false,
opacity: 0.7,
tolerance: 'pointer',
start: function(){
$("#ol-id").removeClass("bottom_dragged");
},
update: function(){
$("#ol-id ol").sortable({disabled : true});
$("#saving_indicator").html("saving...")
$("#saving_indicator").show();
//do other stuff...
}
})
}
Oddly, the error shows up in Firebug as being on the line with update: function(){
.
I have verified that this function is called after both the page is loaded and the jQuery UI library is loaded. I am including both jquery-1.6.2.min.js and jquery-ui-1.8.16.custom.min.js in the header. Moreover, I have verified that all id names are correct and match their HTML counterparts.
So if it's not this missing resource-related stuff, what is causing the problem?
EDIT: here is my HTML header:
<link href="/_css/styles.css?mod=1317745564" type="text/css" rel="stylesheet">
<link href="/_javascript/qtip/jquery.qtip.min.css?mod=1315947301" type="text/css" rel="stylesheet">
<script type="text/javascript" async="" src="http://www.google-analytics.com/ga.js">
<script type="text/javascript" async="" src="http://www.google-analytics.com/ga.js">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
<link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/start/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/le-frog/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js" type="text/javascript">
<script src="/_javascript/sets.js?mod=1320080042" type="text/javascript"> //Sorting stuff code is here
<script type="text/javascript" src="http://dev.selfcheck.vudat.msu.edu/_javascript/jquery.jsonp.js">
<script type="text/javascript" src="http://dev.selfcheck.vudat.msu.edu/_javascript/jquery.form.js">
<script type="text/javascript" src="http://dev.selfcheck.vudat.msu.edu/_javascript/qtip/jquery.qtip.min.js">
<link href="/_css/ui/ui.core.css?mod=1315947279" type="text/css" rel="stylesheet">
<link href="/_css/ui/ui.theme.css?mod=1315947280" type="text/css" rel="stylesheet">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
jQuery UI 和 jQuery 必须按特定顺序加载:
确保在 jQuery 之后包含 jQuery UI。
jQuery UI and jQuery must be loaded in a certain order:
Make sure you are including jQuery UI after jQuery.
所以不确定这是否会对任何人有帮助,但我遇到了类似的情况,我能够解决。 时,似乎会发生这种情况
因此,当a) 加载 jQuery-ui 和 jQuery 的顺序错误
。 b) jQuery 被多次包含,或者包含不同的版本。
选项“b”发生在我身上,因为我使用的是引导模板,其中 jQuery 包含在文档的底部,这当然是最佳实践,而我正在测试的代码在文档的顶部添加了不同版本的 jQuery页面。
我发现这个问题的代码看起来包含许多重复项,所以我建议首先清理它。
So not sure if this will help anyone, but I ran into a similar situation, which I was able to solve. So this seems to happen when either
a) the order of loading jQuery-ui and jQuery is wrong.
b) jQuery is being included more than once, or different versions are being included.
Option "b" happened to me because I was using a bootstrap template, where jQuery is included at the bottom of the document, which is of course a best practice, while the code I was testing added a different version of jQuery at the top of the page.
I see that the code on this question looks like it contains a number of duplicates, so I would suggest cleaning it up as a start.
我遇到了同样的问题,这是因为页面底部包含另一个 js 文件,该文件具有一些 jQuery 函数。当我将其移至页面顶部、位于 jQuery 和 jQuery-UI 上方时,一切都运行良好。
I had the same issue and it was because another js file was being included at the bottom of the page which had some jQuery functions. When I moved this to the top of the page, above my includes of jQuery and jQuery-UI everything works great.
我的问题是我使用 jQuery(...).sortable() 而不是 $(...).sortable()
不知道为什么这很重要,但正在改变它到 $ 修复它。
My issue was I was using jQuery(...).sortable() instead of $(...).sortable()
Not sure why that mattered, but changing it to $ fixed it.
我找到了新的解决方案,
只需在第 551 行编辑 acf.php 文件
旧
新
我刚刚在数组中添加了
jquery-ui-sortable
我希望能帮助某人
谢谢。
i have found new solution,
just edit acf.php file at line number 551
old
new
i just added
jquery-ui-sortable
in arrayi hope help someone
thank you.