【问题标题】:jQuery move div around in DOMjQuery 在 DOM 中移动 div
【发布时间】:2011-04-02 22:29:47
【问题描述】:

我知道这个问题已经被问过很多次了,但我不明白我的代码有什么不正确的地方。

我有一系列DIV“列”,其中包含一些“对象”DIVs。我正在尝试使用下面的代码将对象 DIVs 从一列移动到另一列。

我没有收到任何错误,只是客户端上什么也没有,调试中也没有任何错误提示。

谁能提出以下为什么不起作用?

$(".column-heading").droppable({
    accept: ".column-item",
    drop: function (ev, ui) {
        //alert(this.id);
        //alert(ui.draggable.attr("id"));

        $(ui.draggable.attr("id")).appendTo($(this).parent());
    }
});

我尝试添加/删除的示例列是:

<div class="column">
    <div id="COL_1" class="column-heading">Status 1</div>
    <div id="OBJECT_1" class="column-item">Agreement 1</div>
    <div id="OBJECT_2" class="column-item">Agreement 2</div>
</div>

【问题讨论】:

    标签: javascript html css jquery-ui appendto


    【解决方案1】:

    您需要将 # 连接到带有 ID 的选择器中。

    $('#' + ui.draggable.attr("id")).appendTo(this);
    

    或者,我相信ui.draggable 已经是一个 jQuery 对象,所以试试吧:

    ui.draggable.appendTo(this);
    

    【讨论】:

    • 我知道这很简单!嗬!无论如何,我们生活和学习。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-18
    • 1970-01-01
    • 1970-01-01
    • 2014-09-05
    • 1970-01-01
    相关资源
    最近更新 更多