使用jquery将树节点拖放到动态创建的treeview中的其他根节点中 我找到了答案 function DragNdrop() { $('#tree-view').on('mouseenter mouseover', 'ul>li ul li', function() { $(this).draggable({ revert: true, revertDuration: 0 }); }); $("#tree-view a").closest('li').closest('ul').droppable({ activeClass: "ui-state-default", hoverClass: "ui-state-hover", accept: ":not(.ui-sortable-helper)", drop: function(event, ui) { $(this).find(".placeholder").remove(); $("<li></li>").html(ui.draggable.html()).appendTo(this); } }).sortable({ items: "li:not(.selected)", sort: function() { $(this).removeClass("ui-state-default"); } }); }

使用jquery将树节点拖放到动态创建的treeview中的其他根节点中 我找到了答案 function DragNdrop() { $('#tree-view').on('mouseenter mouseover', 'ul>li ul li', function() { $(this).draggable({ revert: true, revertDuration: 0 }); }); $("#tree-view a").closest('li').closest('ul').droppable({ activeClass: "ui-state-default", hoverClass: "ui-state-hover", accept: ":not(.ui-sortable-helper)", drop: function(event, ui) { $(this).find(".placeholder").remove(); $("<li></li>").html(ui.draggable.html()).appendTo(this); } }).sortable({ items: "li:not(.selected)", sort: function() { $(this).removeClass("ui-state-default"); } }); },jquery,Jquery,这将符合您的要求。我正在努力实现它,但仍然没有运气,请任何人都能帮我。提前谢谢。请任何人都对我感兴趣。我真的很着迷。。请告诉我您需要的任何其他信息。 function DragNdrop() { $('#tree-view').on('mouseenter mouseover', 'ul>li ul li', function() { $(this).draggable({ revert: true, revertDu

这将符合您的要求。

我正在努力实现它,但仍然没有运气,请任何人都能帮我。提前谢谢。请任何人都对我感兴趣。我真的很着迷。。请告诉我您需要的任何其他信息。
function DragNdrop() {
    $('#tree-view').on('mouseenter mouseover', 'ul>li ul li', function() {
        $(this).draggable({
            revert: true,
            revertDuration: 0
        });
    });

    $("#tree-view a").closest('li').closest('ul').droppable({
        activeClass: "ui-state-default",
        hoverClass: "ui-state-hover",
        accept: ":not(.ui-sortable-helper)",
        drop: function(event, ui) {
            $(this).find(".placeholder").remove();
            $("<li></li>").html(ui.draggable.html()).appendTo(this);
        }
    }).sortable({
       items: "li:not(.selected)",
       sort: function() {
            $(this).removeClass("ui-state-default");
       }
   });
}
function DragNdrop() {
   $("#tree-view ul li ul li a").draggable({
    revert: "invalid",
    containment: "document",
    helper: "clone",
    cursor: "move",
    start: function(event, ui) {
        var draggedId = event.target.id;
    }

});

initDroppable($('ul ul a'));
function initDroppable($elements) {
    $elements.droppable({
        activeClass: "ui-state-highlight",
        hoverClass: "droppable-hover",

        drop: function(event, ui) {
            if (confirm('Do you want to move the selected node?')) {
                var draggedId = $(ui.draggable).attr("id");
                var droppedId = $(this).attr("id");

                var getNode = $("#" + draggedId).closest("li");
                var target = $("#" + droppedId).closest('ul');

                if ($(getNode).siblings().length == 0) {
                    $("#" + draggedId).closest("ul").parent('li').removeClass('parent active');
                    $("#" + draggedId).closest("ul").remove();
                    var copyPaste = $(getNode).detach();
                    $(copyPaste).addClass("ui-draggable ui-draggable-handle ui-droppable");
                    $(copyPaste).appendTo(target);
                    HighlightSelectedNode();
                    treeView();
                    DragNdrop();
                }
                else {
                    var copyPaste = $(getNode).detach();
                    $(copyPaste).addClass("ui-draggable ui-draggable-handle ui-droppable");
                    $(copyPaste).appendTo(target);
                    HighlightSelectedNode();
                    treeView();
                    DragNdrop();
                }
                treeView();
            }
            else {//Do Nothing 
            }
        }
    });
}
}