jquery draggable不允许拖动克隆图像

时间:2013-05-06 18:31:57

标签: javascript jquery drag-and-drop

我正在尝试在div中删除图像,在id为 cesta 的div中创建图像克隆,但我只得到禁用的符号。

HTML

<div id='productos' >
   <h3>PRODUCTOS</h3>
   <img id='ali-12' name='serv' class='productos' src='img/objects_139.jpg' />
   <img id='mon-23' name='serv' class='productos' src='img/objects_132.jpg' />
   <img id='zap-32' name='serv' class='productos' src='img/objects_135.jpg' />
   <img id='gua-21' name='serv' class='productos' src='img/objects_102.jpg' />
   <img id='rod-11' name='serv' class='productos' src='img/objects_136.jpg' />
   <img id='maz-44' name='serv' class='productos' src='img/objects_137.jpg' />
   <img id='lla-97' name='serv' class='productos' src='img/objects_138.jpg' />
   <img id='par-10' name='serv' class='productos' src='img/objects_126.jpg' />
   <img id='cru-24' name='serv' class='productos' src='img/objects_121.jpg' />
   <img id='gaf-15' name='serv' class='productos' src='img/objects_131.jpg' />
</div>
<div id='cesta'>
</div>

JAVASCRIPT

$(document).ready(function(){
    $(".productos").draggable({helper:'clone'});  
    $("#cesta").droppable({
        accept: ".productos",
        drop: function(event,ui){
                $(this).append($(ui.draggable).clone());
        }
    });
});

1 个答案:

答案 0 :(得分:0)

您的代码似乎工作正常。我试过这个并且工作得很完美。

除了你粘贴的内容之外,我所做的一切都是:

1)添加了2个库

2)添加了一些css

JS代码与您的代码相同。

<script src="libs/jquery.js"></script>
<script src="libs/jquery_ui.js"></script>

<div id='productos' >
   <h3>PRODUCTOS</h3>
   <img id='ali-12' name='serv' class='productos' src='n-2.png' />
   <img id='mon-23' name='serv' class='productos' src='n-3.png' />
   <img id='zap-32' name='serv' class='productos' src='n-4.png' />
   <img id='gua-21' name='serv' class='productos' src='n-5.png' />
   <img id='rod-11' name='serv' class='productos' src='n-6.png' />
   <img id='maz-44' name='serv' class='productos' src='n-7.png' />
</div>
<div id='cesta'>
<script>
$(document).ready(function(){
$(".productos").draggable({helper:'clone'});  
$("#cesta").droppable({
    accept: ".productos",
    drop: function(event,ui){
            $(this).append($(ui.draggable).clone());
    }
  });
});
</script>

http://jsfiddle.net/janakshah89/sSRXk/1/