我正在玩一些拖放用户界面,我对DROP有点难过。
你可以在这里看到小提琴。
即时目标:
我只需要找出如何让.draggable
跨度进入任何一个.droppable
div。
假设我走在正确的道路上append()
,我该如何访问克隆的内容?
终极目标:
最终,我需要添加一种从放置区 div 中删除项目的方法,并将.textfield
input/div 限制为仅接受一个 drop(.textarea
input/div 可以接受无限数量的“有效负载”)。
代码:
/* html */
<table>
<thead>
<tr role="row">
<th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" style="width: 494px;" aria-sort="ascending" aria-label="Company: activate to sort column descending">Company</th>
<th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" style="width: 66px;" aria-label="Contact">Contact</th>
<th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" style="width: 79px;" aria-label="&nbsp;"> </th>
</tr>
</thead>
<tbody role="alert" aria-live="polite" aria-relevant="all">
<tr class="odd">
<td class="sorting_1 has_draggable_children">
<span draggable="true" class="ui-draggable" data-companyid="0101" data-companyname="**BD">**BD</span>
</td>
<td><a href="#4621">Contacts</a></td>
<td><a href="#4621">Edit</a>
<a href="#4621">Delete</a>
</td>
</tr>
<tr class="even">
<td class="sorting_1 has_draggable_children">
<span draggable="true" data-companyid="0202" data-companyname="0024" class="ui-draggable">0024</span>
</td>
<td><a href="#4438">Contacts</a></td>
<td><a href="#4438">Edit</a>
<a href="#4438">Delete</a>
</td>
</tr>
<tr class="odd">
<td class="sorting_1 has_draggable_children">
<span draggable="true" class="ui-draggable" data-companyid="0303" data-companyname="Acme, Inc.">Acme Anvil Corp</span>
</td>
<td><a href="#4621">Contacts</a></td>
<td><a href="#4621">Edit</a>
<a href="#4621">Delete</a>
</td>
</tr>
</tbody>
</table>
<section class="offset7" id="dragged-drop-zone" >
<div class="look-like-input textfield droppable" contenteditable></div>
<br />
<div class="look-like-input textarea droppable" contenteditable></div>
</section>
.
/* js */
// DRAG
$('span[draggable]').draggable({
revert: true,
helper: "clone"
});
// DROP
$('.droppable').droppable({
tolerance: 'pointer',
drop: function(event, ui) {
//console.log(this);
$(this).append($(ui.helper));
}
});
欢迎任何和所有的帮助和建议