Jquery UI可拖动选择项是可拖动的

时间:2015-05-28 13:59:45

标签: javascript jquery html jquery-ui

我有以下HTML代码:

<div id="match_task_elements_31" class="match_task_draggables ui-draggable">
   <span class="match_task_draggable" id="match_task_draggable_17">Dach</span>
   <span class="match_task_draggable" id="match_task_draggable_16">Tschüss</span>
</div>

现在我希望每个跨度都是一个可拖动的对象,我可以拖动

我尝试了这个JS代码:

$(".match_task_draggables").draggable({handle : '.match_task_draggable'});

但是所以整个div与类match_task_draggables是一个块我可以拖'''

什么出错?

1 个答案:

答案 0 :(得分:1)

尝试以下方法。它允许拖放span

&#13;
&#13;
$(function() {
  $(".match_task_draggable").draggable();
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<div id="match_task_elements_31" class="match_task_draggables ui-draggable">
  <span class="match_task_draggable" id="match_task_draggable_17">Dach</span>
  <span class="match_task_draggable" id="match_task_draggable_16">Tschüss</span>
</div>
&#13;
&#13;
&#13;