简体   繁体   English

jQuery在DOM中移动div

[英]jQuery move div around in DOM

I know this has been asked many times, but I don't understand what is incorrect about my code. 我知道这个问题已经被问过很多次了,但是我不明白我的代码有什么错误。

I have a series of DIV 'columns' containing some 'object' DIV s. 我有一系列包含一些“对象” DIVDIV “列”。 I'm trying to move object DIV s from one column to another using the code below. 我正在尝试使用下面的代码将对象DIV从一列移动到另一列。

I don't receive any errors, just nothing on the client and nothing to suggest in debug that anything is amiss. 我没有收到任何错误,客户端上什么也没有,调试中也没有任何提示是错的。

Can anyone suggest why the following doesn't work? 谁能说出以下原因为何无效?

$(".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());
    }
});

A sample column I am trying add/remove from is: 我尝试从中添加/删除的示例列是:

<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>

You would need to concatenate # into the selector with the ID. 您将需要将#与ID串联到选择器中。

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

Or, I believe ui.draggable is a jQuery object already, so try: 或者,我相信ui.draggable已经是一个jQuery对象,因此请尝试:

ui.draggable.appendTo(this);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM