jQuery UI 排序位置 [英] jQuery UI Sortable Position

查看:20
本文介绍了jQuery UI 排序位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当元素在可排序列表中的位置发生变化时,如何跟踪该元素的位置?

How do I track what position an element is when its position in a sortable list changes?

推荐答案

您可以使用提供给事件的 ui 对象,特别是您想要的 stop 事件ui.item 属性.index(),像这样:

You can use the ui object provided to the events, specifically you want the stop event, the ui.item property and .index(), like this:

$("#sortable").sortable({
    stop: function(event, ui) {
        alert("New position: " + ui.item.index());
    }
});

你可以在这里看到一个工作演示,记住.index()值从零开始,因此您可能需要 +1 以进行显示.

You can see a working demo here, remember the .index() value is zero-based, so you may want to +1 for display purposes.

这篇关于jQuery UI 排序位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆