jquery 可排序警报此列表 id

发布于 2024-11-05 17:54:34 字数 298 浏览 3 评论 0原文

真的需要帮助,

我正在使用 jquery 可排序。

我希望从正在拖动的列表元素中获取 id。

“并非全部关闭”

这是一个示例 http://jsfiddle.net/isimpledesign/85LdV/1/

这会返回一个数组,但我需要它返回正在拖动的元素的 id,以便我可以将其传递给 php 文件。

有人可以帮我解决这个问题吗???

Really need help

i am using jquery sortable.

And i am looking to grab just the id from the list element that is being dragged.

"Not all off them"

Here is an example http://jsfiddle.net/isimpledesign/85LdV/1/

this alerts back an array but i need it to give me back just the id of the element that is being dragged so i can pass it to a php file.

Can someone please help me with this????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

-柠檬树下少年和吉他 2024-11-12 17:54:34

只是为了澄清乍得的答案 -

$(function() {
    $("#sortable").sortable({
        update: function(event, ui) {
            // i need to get the class text that is being dragged i.e
            var order = $(this).sortable("serialize");
            alert(order); 
            /*
             No need to bind any other events, ui.item is the dragged
             item in 'update' too and we only want to capture the id when the sort
             has changed presumably
            */
            alert(ui.item.attr('id'));
            /*
             No need for subscripting, ui.item is a jquery object so 
             we can just call attr() on it to get the ID
            */
        }
    });
});

Just to clarify Chad's answer a bit -

$(function() {
    $("#sortable").sortable({
        update: function(event, ui) {
            // i need to get the class text that is being dragged i.e
            var order = $(this).sortable("serialize");
            alert(order); 
            /*
             No need to bind any other events, ui.item is the dragged
             item in 'update' too and we only want to capture the id when the sort
             has changed presumably
            */
            alert(ui.item.attr('id'));
            /*
             No need for subscripting, ui.item is a jquery object so 
             we can just call attr() on it to get the ID
            */
        }
    });
});
北城孤痞 2024-11-12 17:54:34

使用 start 事件:

$(function() {
   $("#sortable").sortable({
      update: function(event, ui) {
         // i need to get the class text that is being dragged i.e
        var order = $(this).sortable("serialize");
        alert(order);   
      },
      //Start event fires on the start of a sort
      //you can store the id from in here
      start: function(event, ui) {
         //here ui.item contains a jquery object that is the item being dragged
         alert(ui.item[0].id);
      }
   });
});

Use the start event:

$(function() {
   $("#sortable").sortable({
      update: function(event, ui) {
         // i need to get the class text that is being dragged i.e
        var order = $(this).sortable("serialize");
        alert(order);   
      },
      //Start event fires on the start of a sort
      //you can store the id from in here
      start: function(event, ui) {
         //here ui.item contains a jquery object that is the item being dragged
         alert(ui.item[0].id);
      }
   });
});
夜光 2024-11-12 17:54:34

使用这个:

$(function() {
    var lastMoved = null;
    $("#sortable li").mousedown(function(){
        lastMoved = this;
    });
    $("#sortable").sortable({
      update: function(event, ui) {
        alert($(lastMoved).attr("id"));
      }
    });
});

它已经过测试并且可以工作。
希望这有帮助。干杯。

Use this:

$(function() {
    var lastMoved = null;
    $("#sortable li").mousedown(function(){
        lastMoved = this;
    });
    $("#sortable").sortable({
      update: function(event, ui) {
        alert($(lastMoved).attr("id"));
      }
    });
});

It's tested and working.
Hope this helps. Cheers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文