javascript - 如何将元素放回到前一个位置?

标签 javascript jquery jquery-ui-sortable

我知道如何获取顺序,但我不知道如何在必要时将元素放回到操作之前的先前位置。

请多多指教,非常感谢。

el.sortable({
    start: function(){   var order = etc //Got current order here//  },

    update: function(){
         //Process and etc//

         if(cancel) {
            //how can I put the element back to the position before??
         }

    },


});

最佳答案

$( ".selector").sortable( "cancel") 将起作用(在初始化可排序之后,当然,不在初始化内部)

el.sortable({
    start: function(){   var order = etc //Got current order here//  },

    update: function(){
         //Process and etc//

         if(cancel) { //NO NOT HERE
            //how can I put the element back to the position before??
         }

    },


});

el.sortable("cancel"); //here

参见http://api.jqueryui.com/sortable/#method-cancel

cancel()

Cancels a change in the current sortable and reverts it to the state prior to when the current sort was started. Useful in the stop and receive callback functions. This method does not accept any arguments.

关于javascript - 如何将元素放回到前一个位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14227448/

相关文章:

css - jQuery UI 可排序和 :active mouse cursor for handle

javascript - 使用 Mongoose 更新数组中的特定对象时出错

javascript - 异步函数回调时未调用 VueJS 方法

javascript - 在 Node Express 路由中使用句点时收到 403

javascript - Angular-Datatables 日期排序错误

jquery - 如何使用jquery更改按钮的值

php - 使用 JQuery 可排序新值更新 MySQL

javascript - 用 "..."替换太长的字符串

javascript - 点击事件在 map 上方不起作用

javascript - JQuery 可排序嵌套可排序 div