0
我有2个表:Jquery的拖/放拷贝的细胞内容而不是移动
- 表1保持了能够表2.
- 表2可以由被更新内被复制到任何位置的静态数据从表1 OR或复制的数据移动数据在此表中。
一切正常,除了移动。它当我拖/放副本的内容。
有人有线索吗?
在这里,你可以看看online sample:
我有2个表:Jquery的拖/放拷贝的细胞内容而不是移动
一切正常,除了移动。它当我拖/放副本的内容。
有人有线索吗?
在这里,你可以看看online sample:
我解决了这个问题,周围的工作。我现在只是从原来的TD中删除内容。我添加了一张额外的桌子作为垃圾桶。
在线样本做它应该做的一切。但是,我不确定这是否是最有效的方法。如果涉及到jquery,我相当缺乏经验。
因此,如果任何人有一个更优雅的解决方案,做同样的事情,我很愿意学习:)
以防万一,这里是JQ-码我用:
jQuery(function($) {
var td1 = $("#table1 td");
var td2 = $("#table2 td");
var bin = $("#trash td");
td1.draggable({
cursor: "move",
appendTo: "body",
helper: "clone",
opacity: "0.5",
revert: "invalid"
});
td2.draggable({
cursor: "move",
appendTo: "body",
helper: "clone",
opacity: "0.5",
revert: "invalid"
});
td2.droppable({
accept: 'td',
tolerance: "pointer",
drop: function (event, ui) {
// check from which table we are dragging
var fromTable = $(ui.draggable).closest("table").attr("id");
// check from which td we are dragging
var fromTD = $(ui.draggable).attr("id");
// get the inner html content for the td we are dragging the div from
var cell = $(ui.draggable).html();
// insert the complete html content into the target drop cell
$(this).html(cell);
// for purposes of result logging/debugging
var location = $(this).attr('id');
$('#result').html('Moved '+cell+'<br>From '+fromTable+'/'+fromTD+' (table/td)<br>To cell: '+location+'<br>complete with containing DIV');
// in case we moved cell content within table2, remove the original content
if(fromTable == "table2"){
$(ui.draggable).html('<div></div>');
}
}
});
bin.droppable({
accept: 'td',
tolerance: "pointer",
drop: function (event, ui) {
// check if we are dragging from table 2
var fromTable = $(ui.draggable).closest("table").attr("id");
if(fromTable != "table2"){
$('#result').html('You cannot move content<br>from '+fromTable+' to the trash bin...');
return false;
}
else {
// check from which td we are dragging
var fromTD = $(ui.draggable).attr("id");
// get the inner html content for the td we are dragging the div from
var cell = $(ui.draggable).html();
// insert the complete html content into the target drop cell
$(this).html(cell);
// for purposes of result logging/debugging
var location = $(this).attr('id');
$('#result').html('Moved '+cell+'<br>From '+fromTable+'/'+fromTD+' (table/td)<br>To the trash bin');
// replace the content of the source td after drop
$(ui.draggable).html('<div></div>');
}
}
});
});