【发布时间】:2014-12-25 09:38:33
【问题描述】:
这是我的小提琴:FIDDLE
期望:当我双击任何空的TD时,自己的TR的可拖动元素可以自动拖放到那个TD。
我搜索了很多,但找不到完美的解决方案。
我的 JS 代码
$(function () {
$(".dragDiv").draggable({
revert: 'invalid'
});
$(".mainTable tr td").droppable({
accept: function (item) {
return $(this).closest("tr").is(item.closest("tr")) && $(this).find("*").length == 0;
},
drop: function (event, ui) {
console.log($(this).attr('id'));
console.log(ui.draggable.attr('id'));
var $this = $(this);
$this.append(ui.draggable.css({
top: 0,
left: 0
}));
ui.draggable.position({
my: "center",
at: "center",
of: $this,
using: function (pos) {
$(this).animate(pos, "slow", "linear", function () {
});
}
});
}
});
});
【问题讨论】:
标签: jquery jquery-ui drag-and-drop draggable droppable