首先,对不起我的英语。
我的问题如下:
我有 3 个列表,将 2 拖到列表 1 中,将列表 3 拖到列表 2 中,但是如果我在列表 1 中动态添加项目,我无法拖动,这里是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Pedidos</title>
<link rel="stylesheet"
href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
margin-bottom: 10px;
}
li {
margin: 5px;
padding: 5px;
width: 150px;
}
</style>
<script>
$(function() {
$("#cozinha li, #garcom li").draggable({
revert : "invalid",
containment : "document",
helper : "clone",
cursor : "crosshair"
});
$("#garcom ol").droppable({
activeClass : "ui-state-default",
hoverClass : "ui-state-hover",
accept : "#cozinha li",
greedy : true,
drop : function(event, ui) {
$(this).find(".placeholder").remove();
$("<li></li>").text(ui.draggable.text()).appendTo(this);
ui.draggable.remove();
}
}).sortable({
items : "li:not(.placeholder)",
sort : function() {
$(this).removeClass("ui-state-default");
}
});
$("#caixa ol").droppable({
activeClass : "ui-state-default",
hoverClass : "ui-state-hover",
accept : "#garcom li",
greedy : true,
drop : function(event, ui) {
$(this).find(".placeholder").remove();
$("<li></li>").text(ui.draggable.text()).appendTo(this);
ui.draggable.remove();
}
}).sortable({
items : "li:not(.placeholder)",
sort : function() {
$(this).removeClass("ui-state-default");
}
});
});
</script>
<script type="text/javascript">
jQuery(function($) {
setInterval(function() {
$.getJSON('pedidos', function(events) {
for ( var i in events) {
$('#cozinha ol').append(
'<li class="ui-state-highlight">' + events[i]
+ '</li>');
}
});
}, 6000);
});
</script>
</head>
<body>
<div id="cozinha">
<ol style="float: left; width: 30%">
<li class="ui-state-highlight">Col3 1</li>
<li class="ui-state-highlight">Col3 2</li>
<li class="ui-state-highlight">Col3 3</li>
<li class="ui-state-highlight">Col3 4</li>
<li class="ui-state-highlight">Col3 5</li>
</ol>
</div>
<div id="garcom">
<ol style="float: left; width: 30%">
<li class="placeholder">Adicione Aqui</li>
</ol>
</div>
<div id="caixa">
<ol style="float: left; width: 30%" class="sortable-class">
<li class="placeholder">Adicione Aqui</li>
</ol>
</div>
</body>
</html>