http://jsbin.com/IZodOSU/1/edit
所有具有拖动类的 div 都应该是可拖动的,但是当添加一个时,它是不可拖动的。谁能帮我解决这个问题?
HTML
<script src="http://threedubmedia.com/inc/js/jquery-1.7.2.js"></script>
<script src="http://threedubmedia.com/inc/js/jquery.event.drag-2.2.js"></script>
<script src="http://threedubmedia.com/inc/js/jquery.event.drag.live-2.2.js"></script>
<button id="divgen">Gen Div</button>
<div class="container">
<div class="drag" style="left:20px;"></div>
<div class="drag" style="left:100px;"></div>
<div class="drag" style="left:180px;"></div>
</div>
CSS
.drag {
position: absolute;
border: 1px solid #89B;
background: #BCE;
height: 58px;
width: 58px;
cursor: move;
top: 120px;
}
JS/jQuery
jQuery(function($){
$('.drag').drag(function( ev, dd ){
$( this ).css({
top: dd.offsetY,
left: dd.offsetX
});
});
$("#divgen").click(function() {
$("div.container").append('<div id="whatever" class="drag">my div</div>');
});
});