我已经创建了拖放工作。在这里,我可以将拖动内容放置到特定区域,但我已经为可拖动项目创建了每个可放置功能。我需要简化一下。
$(document).ready(function() {
$(".list").draggable({
helper: 'clone',
cursor: 'hand',
revert: true,
drag: function(ev, ui) {
dragId = $(this).attr('id');
}
});
$("#td1").droppable({
accept: '#1',
activeClass: 'drop-active',
hoverClass: 'dropareahover',
drop: function(event, ui) {
var targetId = $(this).attr("id");
$("#" + targetId).each(function() {
$(this).append(ui.draggable.text());
});
}
});
$("#td2").droppable({
accept: '#1',
activeClass: 'drop-active',
hoverClass: 'dropareahover',
drop: function(event, ui) {
var targetId = $(this).attr("id");
$("#" + targetId).each(function() {
$(this).append(ui.draggable.text());
});
}
});
$("#td3").droppable({
accept: '#2',
activeClass: 'drop-active',
hoverClass: 'dropareahover',
drop: function(event, ui) {
var targetId = $(this).attr("id");
$("#" + targetId).each(function() {
$(this).append(ui.draggable.text());
});
}
});
$("#td4").droppable({
accept: '#2',
activeClass: 'drop-active',
hoverClass: 'dropareahover',
drop: function(event, ui) {
var targetId = $(this).attr("id");
$("#" + targetId).each(function() {
$(this).append(ui.draggable.text());
});
}
});
$("#td5").droppable({
accept: '#3',
activeClass: 'drop-active',
hoverClass: 'dropareahover',
drop: function(event, ui) {
var targetId = $(this).attr("id");
$("#" + targetId).each(function() {
$(this).append(ui.draggable.text());
});
}
});
$("#td6").droppable({
accept: '#3',
activeClass: 'drop-active',
hoverClass: 'dropareahover',
drop: function(event, ui) {
var targetId = $(this).attr("id");
$("#" + targetId).each(function() {
$(this).append(ui.draggable.text());
});
}
});
$("#td7").droppable({
accept: '#4',
activeClass: 'drop-active',
hoverClass: 'dropareahover',
drop: function(event, ui) {
var targetId = $(this).attr("id");
$("#" + targetId).each(function() {
$(this).append(ui.draggable.text());
});
}
});
$("#td8").droppable({
accept: '#4',
activeClass: 'drop-active',
hoverClass: 'dropareahover',
drop: function(event, ui) {
var targetId = $(this).attr("id");
$("#" + targetId).each(function() {
$(this).append(ui.draggable.text());
});
}
});
});
这是我的工作:http: //jsfiddle.net/thilakar/u7TnA/
请帮帮我。
谢谢