0
我想創建一個表格,其中每個單元格可以包含可以在其他單元格中拖放的元素(div)。 看來,該元素可以只刪除原始div。 我不明白爲什麼它不起作用。多個div中的jQuery可拖動/可放置div
<style>
.over {
border: solid 4px #ACFA58;
}
.draggable {
border: solid 4px red;
width:150px;
height:75px;
}
#timetable{
margin-top:50px;
width:100%;
border-collapse:collapse;
border: 1px solid black;
}
#timetable th{
text-align:center;
}
#timetable td{
width:150px;
height:75px;
border: 1px solid black;
}
</style>
<script>
$(document).ready(function() {
$(".draggable").draggable({
cursor: "crosshair",
revert: "invalid"
});
$(".drop").droppable({
accept: ".draggable",
drop: function(event, ui) {
console.log("drop");
$(this).removeClass("border").removeClass("over");
var dropped = ui.draggable;
var droppedOn = $(this);
$(dropped).detach().css({top: 0,left: 0}).appendTo(droppedOn);
},
over: function(event, elem) {
$(this).addClass("over");
console.log("over");
},
out: function(event, elem) {
$(this).removeClass("over");
}
});
$(".drop").sortable();
});
</script>
<div id="page-wrapper">
<table id="timetable" >
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
<th>7</th>
</tr>
</thead>
<tbody id="containment">
<tr>
<td><div class="drop"><div class="draggable"></div></div></td>
<td><div class="drop"></div></td>
<td><div class="drop"></div></td>
<td><div class="drop"></div></td>
<td><div class="drop"></div></td>
<td><div class="drop"></div></td>
<td><div class="drop"></div></td>
</tr>
<tr>
<td><div class="drop"></div></td>
<td><div class="drop"></div></td>
<td><div class="drop"></div></td>
<td><div class="drop"></div></td>
<td><div class="drop"></div></td>
<td><div class="drop"></div></td>
<td><div class="drop"></div></td>
</tr>
</tbody>
</table>
</div><!-- /#page-wrapper -->