【问题标题】:Add items to sortable将项目添加到可排序
【发布时间】:2017-10-11 19:12:00
【问题描述】:

我会使用 jqueru ui 和 sortable,但是我犯了一些愚蠢的错误,我无法更改“entry-add”项添加的项。

演示:https://jsfiddle.net/7p0w1gpe/3/

$(function() {
  $('.test').sortable({
    connectWith: ".test"    
  }).disableSelection();
});

【问题讨论】:

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


    【解决方案1】:

    您正在将 connectWith 应用到已经存在的带有测试类的 div。当您使用类测试添加一个新 div 并使其可排序时,您忘记同时添加 connectWith。

    我已经在下面的小提琴中添加了它。

    https://jsfiddle.net/ksxLymox/

      $(function() {
    $('.test').sortable({
      connectWith: ".test",
    
    }).disableSelection();
      });
    
      $(document).on('click', '.add-done', function() {
        $('<div id="sortable1" class="test connectedSortable"><a class="ui-state-default">Item 1</a></div>').insertBefore('.add-done').sortable({connectWith: ".test"});
        console.log("add");
      });
    
      $(document).on('click', '.entry-add', function() {
        $(this).parent().find('.test').append('<a href="#">new items</a>').sortable({connectWith: ".test"});
      });
    

    为了使您的代码更好,您可以重用一个函数来使 div 可排序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-10
      • 2018-06-17
      相关资源
      最近更新 更多