每次拖放后向 table 插入一个新行以接受下一次拖放 - 我的代码仅适用于第一次拖放
After each drag and drop insert a new row to the table to accept the next drag and drop - my code only works on the first drag and drop
当我拖放一个项目时,我想在最后插入一个新行到 table,以接受下一次拖放。在我下面的代码中,这只有效一次。在第二次拖放时,新行未插入 table。下面的最后一行代码插入新行:
($('#activity2Tablebody').append("<td><div class='droppableItem'></td>");).
function makeDraggable() {
$('.dragabbleItem').draggable({
stack: ".dragabbleItem",
cursor: 'pointer',
helper: 'clone',
drag: function( event, ui ) {
//Make the row/field being dragged to droppable
makeDroppable();
}
});
}
function makeDraggableRemove() {
//This item will be deleted when dragged
$('.dragabbleRemove').draggable({
cursor: 'pointer',
drag: function( event, ui ) {
//Remove this row from the table
$(this).remove();
}
});
}
function makeDroppable() {
$('.droppableItem').droppable({
hoverClass: 'hovered',
drop: function( event, ui ) {
var droppable = $(this);
var draggable = ui.draggable;
alert( 'The item with ID "' + draggable.attr('id') + '" was dropped onto me!' );
// Move draggable into droppable
var drag = $('.droppableItem').has(ui.draggable).length ? draggable : draggable.clone().draggable({
revert: "invalid",
stack: ".dragabbleItem",
helper: 'clone'
});
//Add the dragged item to the row/field
drag.appendTo(droppable);
//Stop the dropped item from being draggable
drag.draggable('disable');
//Format the row/field dropped into with a blue background
droppable.css({top: '5px', left: '5px', background: '#B0C4DE'});
//Do not allow another item to be dropped into this row/field
droppable.droppable('disable');
//If this row/filed is dragged then remove it
droppable.addClass("dragabbleRemove");
makeDraggableRemove();
//Add a new row/field to drag to
$('#activity2Tablebody').append("<td><div class='droppableItem'></td>");
}
});
}
您应该附加到 table 正文 <tr><td>
- table 行和单元格,而不仅仅是 <td>
当我拖放一个项目时,我想在最后插入一个新行到 table,以接受下一次拖放。在我下面的代码中,这只有效一次。在第二次拖放时,新行未插入 table。下面的最后一行代码插入新行:
($('#activity2Tablebody').append("<td><div class='droppableItem'></td>");).
function makeDraggable() {
$('.dragabbleItem').draggable({
stack: ".dragabbleItem",
cursor: 'pointer',
helper: 'clone',
drag: function( event, ui ) {
//Make the row/field being dragged to droppable
makeDroppable();
}
});
}
function makeDraggableRemove() {
//This item will be deleted when dragged
$('.dragabbleRemove').draggable({
cursor: 'pointer',
drag: function( event, ui ) {
//Remove this row from the table
$(this).remove();
}
});
}
function makeDroppable() {
$('.droppableItem').droppable({
hoverClass: 'hovered',
drop: function( event, ui ) {
var droppable = $(this);
var draggable = ui.draggable;
alert( 'The item with ID "' + draggable.attr('id') + '" was dropped onto me!' );
// Move draggable into droppable
var drag = $('.droppableItem').has(ui.draggable).length ? draggable : draggable.clone().draggable({
revert: "invalid",
stack: ".dragabbleItem",
helper: 'clone'
});
//Add the dragged item to the row/field
drag.appendTo(droppable);
//Stop the dropped item from being draggable
drag.draggable('disable');
//Format the row/field dropped into with a blue background
droppable.css({top: '5px', left: '5px', background: '#B0C4DE'});
//Do not allow another item to be dropped into this row/field
droppable.droppable('disable');
//If this row/filed is dragged then remove it
droppable.addClass("dragabbleRemove");
makeDraggableRemove();
//Add a new row/field to drag to
$('#activity2Tablebody').append("<td><div class='droppableItem'></td>");
}
});
}
您应该附加到 table 正文 <tr><td>
- table 行和单元格,而不仅仅是 <td>