首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery可排序和可下垂-不能将项目从1列表克隆到另一列表。

Jquery可排序和可下垂-不能将项目从1列表克隆到另一列表。
EN

Stack Overflow用户
提问于 2013-10-29 06:22:32
回答 1查看 293关注 0票数 0

从列表2到列表1,我想克隆元素。

我用的是可排序的和便便的。但是克隆部分是行不通的!

小提琴手:http://jsfiddle.net/46zqm/6/

代码语言:javascript
复制
As you can see cloned part gets stuck in the tab navli.

完整代码:

代码语言:javascript
复制
    // Initiate jquery ui sortable
    $(".word-list").sortable({
        tolerance: 'pointer',
        cursor: 'move',
        forcePlaceholderSize: true,
        dropOnEmpty: true,
        connectWith: 'ol.word-list',
        placeholder: "ui-state-highlight"
    }).disableSelection();

// Words tabs
    var $tabs = $("#tabs").tabs({active: 1});

    // Make tab names dropable
    var $tab_items = $("#tabs-nav li", $tabs).droppable({
      accept: ".word-list li",
      hoverClass: "ui-state-hover",
      tolerance: 'pointer',
      drop: function(event,ui) {

        // Deduce source and target
        var source = $(ui.draggable[0]).parent().attr("id").split("-")[1];
        var target = $(event.target).children("a").attr("href").split("-")[1];
        // 1 = Top words, 2 = All words, 3 = Deleted
        console.dir("source:" + source); 
        console.dir("target:" + target);
        // If droped on self, do nothing
        if (source == target) {return false;}

        // 
        var $item = $(this);
        var $list = $($item.find("a").attr("href"));

        if (source == 2 && target == 1) {
          $tabs.tabs("option", "active", $tab_items.index($item));
          ui.draggable.clone().appendTo($list);
        } else {
          ui.draggable.hide("fast", function() {
            $tabs.tabs("option", "active", $tab_items.index($item));
            $(this).appendTo($list).show("slow");
          });
        }
      }
    });
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-29 07:39:14

问题是,克隆的元素保持了从中克隆的掺杂元素的内联位置。

您可以使用removeAttr('style')重置其内联样式。

代码:

代码语言:javascript
复制
// Make tab names dropable
var $tab_items = $("#tabs-nav li", $tabs).droppable({
  accept: ".word-list li",
  hoverClass: "ui-state-hover",
  tolerance: 'pointer',
  drop: function(event,ui) {

    // Deduce source and target
    var source = $(ui.draggable[0]).parent().attr("id").split("-")[1];
    var target = $(event.target).children("a").attr("href").split("-")[1];
    // 1 = Top words, 2 = All words, 3 = Deleted
    // If droped on self, do nothing
    if (source == target) {return false;}

    // 
    var $item = $(this);
    var $list = $($item.find("a").attr("href"));

    var $dragged=ui.draggable.clone().removeAttr('style');  

    if (source == 2 && target == 1) {
        $tabs.tabs("option", "active", $tab_items.index($item));
        $dragged.appendTo($list);
    } else {
        ui.draggable.hide("fast", function() {
          $tabs.tabs("option", "active", $tab_items.index($item));
          $(this).appendTo($list).show("slow");
        });
    }
  }

演示:http://jsfiddle.net/H6pVW/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19651111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档