如何在元素被拖出容器之外删除元素

时间:2017-10-01 02:56:24

标签: jquery-ui drag-and-drop jquery-ui-draggable jquery-ui-droppable

<div class='container'>
<div class='element'>lorem ipsum</div>
<div class='element'>lorem ipsum</div>
<div class='element'>lorem ipsum</div>
<div class='element'>lorem ipsum</div>
</div>

$('.container').sortable({
stop: function(event, ui) {
    ui.item.remove(); 
}
});

这样做但我只有在element之外被拖动时才需要删除container,如果它在container内排序,则需要删除。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您只需在function ExportResults() { startDate=document.getElementById("Start_Date").value; endDate=document.getElementById("End_Date").value; $('#OrderTable').table2excel({ exclude: ".excludeThisClass", name: "Excel Document Name", filename: "Search Results (" + startDate + "-" + endDate + ")", //do not include extension fileext: ".xls", // MUST use .xls extension, only this will work }); } 中定义accept,就像这样:

<强> jsfiddle

<强> HTML

droppable

<强>的JavaScript

<div class="element">Drag me</div>
<div id="content">
  <div class="container">
   drop here (container)
  </div>
</div>