javascript - jQueryUI 多个可放置元素

标签 javascript jquery jquery-ui

为什么当我将我的 draggable div 拖到 droppable1 div 时,它总是被放置在 droppable2 div 中。

此外,我遵循了 jQuery UI 回弹选项,但它不起作用。我怎么能做到这一点,而不是拖动实际的 draggable 元素,而是拖动它的一个实例/副本,并让 droppable 接受其中的多个 draggable元素。

<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
  $(function() {
    $( '#draggable' ).draggable();

    $( '#droppable1' ).droppable({
      drop: function(event, ui)
      {
        $(this)
          .append(ui.draggable.css({position: 'relative', left: '0px', top: '0px'}));
      }
    });

    $( '#droppable2' ).droppable({
      drop: function(event, ui)
      {
        $(this)
          .append(ui.draggable.css({position: 'relative', left: '0px', top: '0px'}));
      }
    });



  });
</script>

<div class="well">
  <div id="draggable">CONTENT</div>
</div>

<div id="droppable1" class="well col-md-3" style="z-index:-1;"></div>
<div id="droppable2" class="well col-md-9" style="z-index:-1;"></div>

最佳答案

您可以使用接受 过滤器接受特定可放置区域中的特定项目。

$( '#droppable1' ).droppable({
      accept: '#draggable',
      drop: function(event, ui)
      {
        $(this)
          .append(ui.draggable.css({position: 'relative', left: '0px', top: '0px'}));
      }
    });

关于javascript - jQueryUI 多个可放置元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19251597/

相关文章:

javascript - PHP "PUSH"到 Javascript

jquery - 如何将单个项目附加到 jQuery UI 自动完成结果集下拉列表中?

javascript - onclick 复选框将复选框值附加到 URL

visual-studio - 在 .net 核心应用程序中通过 nuget 安装 jquery ui 后找不到文件

javascript - 保留 :hover on dragging jquery element

javascript - NODE.JS 使用 audioconcat ,配置了 ffmpeg 但仍然有问题

javascript - 使用基本方法在 JavaScript 中将数字拆分为单独的数字

javascript - 如果安装了插件,如何检查 Firefox 和 Chrome

javascript - 将 jQuery/JavaScript 函数应用于 jTable 检索的 SQL 数据

javascript - JSON JQUERY 未捕获类型错误 : Cannot read property 'length' of undefined