【问题标题】:Jquery Sortable won't alert "order" on updateJquery Sortable 不会在更新时提醒“订单”
【发布时间】:2013-02-27 12:17:34
【问题描述】:

这应该是直截了当的,但是我在提醒我的可排序列表的顺序时遇到了麻烦。

这是我正在使用的 JQuery 代码:

$(document).ready(function() {
    $("#projectItems").sortable({
        update : function(event, ui) {
            var order = $(this).sortable('toArray').toString();
            alert(order);

        }
    });
});

这是我的列表的 HTML:

<ul id="projectItems">
                    <li id="item1" value="<?php echo $studentChoice1; ?>">(1) <?php echo $title[1]; ?><a href='#message1' onclick='deleteProject(".$studentChoice1.",".$userID.")'><img height=20px width=20px alt='Delete' src='img/delete.png' /></a></li>
                    <li id="item2" value="<?php echo $studentChoice2; ?>">(2) <?php echo $title[2]; ?><a href='#message1' onclick='deleteProject(".$studentChoice2.",".$userID.")'><img height=20px width=20px alt='Delete' src='img/delete.png' /></a></li>
                    <li id="item3" value="<?php echo $studentChoice3; ?>">(3) <?php echo $title[3]; ?><a href='#message1' onclick='deleteProject(".$studentChoice3.",".$userID.")'><img height=20px width=20px alt='Delete' src='img/delete.png' /></a></li>
                    <li id="item4" value="<?php echo $studentChoice4; ?>">(4) <?php echo $title[4]; ?><a href='#message1' onclick='deleteProject(".$studentChoice4.",".$userID.")'><img height=20px width=20px alt='Delete' src='img/delete.png' /></a></li>
                    <li id="item5" value="<?php echo $studentChoice5; ?>">(5) <?php echo $title[5]; ?><a href='#message1' onclick='deleteProject(".$studentChoice5.",".$userID.")'><img height=20px width=20px alt='Delete' src='img/delete.png' /></a></li>
</ul>

该列表是可排序的并且有效,但是当用户完成对项目的排序时,它根本不会显示警报消息。

这里的任何帮助将不胜感激,因为我已经被这个问题困扰了几天,似乎无法在线找到解决方案。

更新 问题似乎在于引用 jQuery

我正在使用的 jQuery 的当前版本是 1.7.1,来自 google 的 CDN,在我的脚本中引用如下:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

但是,当我将其更改为:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

根本没用!

当我尝试像下面这样的引用时,它说有一个 jquery 引用错误!

<link href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" href="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" href="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>

我不知道如何解决这个问题,因为它似乎对其他人都很好! 在这里的任何帮助将不胜感激。

【问题讨论】:

标签: jquery jquery-ui jquery-ui-sortable


【解决方案1】:

它工作正常,检查这里:http://jsfiddle.net/DHJb7/

$(document).ready(function() {
$("#projectItems").sortable({
    update : function(event, ui) {
        var order = $(this).sortable('toArray').toString();
        alert(order);
    }
});
});

我想你忘了包含 jQuery 或 jQueryUI 库。 如果您已包含它们,请检查库的版本。

推荐版本: 1.9.1 for jQuery 和 1.9.2 for jQueryUI

<link href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" href="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" href="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>

【讨论】:

  • 您好,感谢您的快速回复,我认为这是我的问题。我像这样引用 jquery:
  • 再次感谢您的更新。这仍然对我不起作用,现在我有 1.9.1 版本的 jquery 而不是 1.7.1,列表不再可排序!我真的在这里迷失了为什么它不能正常工作。
  • 我已经在 css 的链接中添加了,现在也如上所示,它仍然可以正常工作。 (现在不允许任何项目可排序)
  • 当我尝试像上面那样引用时,Firebug 返回 jQuery 引用错误?为什么会发生这种情况?它现在似乎只适用于 ajax.googleapis/../1.7.1 但不适用于 1.9.1
【解决方案2】:

看看这个fiddle链接,它对我来说很好用。

         $("#projectItems").sortable({
                update: function (event, ui) {
                    var order = $(this).sortable('toArray').toString();
                    alert(order);

                }
          });

我希望这对你有更多帮助。

【讨论】:

    【解决方案3】:

    它应该可以工作。添加 jquery ui 和 jquery 库。 只是为了清楚你需要改变位置 的项目(通过拖放)来调用您想要的功能(更新)。

    【讨论】:

      猜你喜欢
      • 2012-04-06
      • 1970-01-01
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      • 2012-08-18
      • 2016-03-14
      • 1970-01-01
      • 2018-10-12
      相关资源
      最近更新 更多