繁体   English   中英

放入动态创建的div后,jQuery-ui Draggable无法正常工作

[英]Jquery-ui draggable not working after dropping into dynamically created div

一旦将div放到可放置的绑定div中,就无法拖动它。

我有多个设置为可拖放的行,其中插入了诸如文本框,复选框等控件。 并且每个控件都包含可拖动的div。

第一次将列拖放到可放置的绑定div中时,它可以正常工作,然后可拖动停止。 删除div后,我尝试重新初始化可拖动对象,但它也无法解决。

以下是我为每一列实施的方法,之后将这些列附加到一个容器中以进行渲染:

function buildRow()
{
   var formRow = $("div").attr('id', 'mainform')
                    .attr('rowIndex', rowIndex)
                    .attr('class', 'formrow ')
                    .attr('style', 'width: 100%;min-height:100px)
                    .droppable({
                        accept: "#formColumn",
                        drop: function (event, ui) {

                            $(ui.draggable).draggable('destroy').draggable({
                                containment: $('#formControlsPlaceholder'),
                                cursor: 'move'
                            });

                        }
                    });

var formColumn = $('<div>')
                    .attr('id', 'formColumn')
                    .attr('style', 'width:80%;max-width:100%;')
                    .draggable({
                        containment: $('#container'),
                        cursor: 'move'
                    });
 }

实际上,这个问题不是可拖动的。 在将元素或控件拖放到新行时,我使用了attr('style')为其内部的所有元素提供相等的宽度。 但是我不知道设置attr('style')会替换所有现有样式,因此Draggable与DOM的绑定也被破坏了。

一旦将attr('style')替换为css('width','sth'),它就起作用了。

:D

达拉杰(Dhiraj Dhakal)

暂无
暂无

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

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