我想通过单击并拖动将div_1复制到div_2中。但是即使将div_1复制到div_2后也要保持其位置不变。仅在onclick中有效,请帮助我如何通过上述功能在拖放中完成。提前致谢...!

$(document).ready(function()
{
    $('.div_1').on('click',function()
    {
        $('.div_1').appendTo('.div_2');
    });
});


我在Jsfiddle ..中的代码!

最佳答案

助手将使您能够将原始元素保持在相同位置

$(".div_1").draggable({
    //revert: "valid",
    //clone the element which is dragged
    helper: "clone",
    //draggable area in which it is acceptable
    containment: "container",
    // cursor pointer style
    cursor: "move",
    stop: function () {
        $(this).draggable('option', 'revert', 'invalid');

    }
});

并将div_2设置为droppable即可接受div_1
$(".div_2").droppable({
        drop: function (event, ui)
              {
              alert(ui);
              }
})

10-04 16:08