Jquery Sortable不会在更新时提醒“订单”

时间:2013-02-27 12:17:35

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

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

这是我正在使用的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的当前版本是来自google的CDN的1.7.1,如下所示在我的脚本中引用:

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

我不知道如何解决这个问题,因为它似乎对其他人都很好! 非常感谢任何帮助。

3 个答案:

答案 0 :(得分:2)

工作正常,请点击此处: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用于jQuery,1.9.2用于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>

答案 1 :(得分:0)

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

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

                }
          });

我希望这会对你有所帮助。

答案 2 :(得分:0)

IT应该有效。添加jquery ui和jquery库。 只是要明确你需要改变立场 项目(通过拖放)来调用你想要的功能(更新)。

相关问题