我在从用作拖放框的框中获取值时遇到问题。框可以正确拖放,而且我可以用值更新div,但我希望将拖动框中的值与拖动框的框的值一起放在我正在附加的div中。这是迄今为止的代码。如有任何帮助,将不胜感激
这是我到目前为止所拥有的,以及我在上制作代码的页面链接
<script>
$(function() {
// make orange boxes draggable
$( ".draggable" ).draggable();
//make blue boxes draggable but also make things mappen when orange box is dropped in it
$( ".droppable" ).draggable().droppable({
drop: function( event, ui ) {
var targetElem = $(this).attr("title");
// update the div at the top of the page with the value of the blue box being dropped on and the orange box being dragged
$('#showstuff').empty();
$('#showstuff').append('' + targetElem + '');
}
});
// when an orange box is dragged away from the blue box append the #showstuff div
$( ".droppable" ).draggable().droppable({
out: function(event, ui) {
$('#showstuff').empty();
$('#showstuff').append('emptied again');
}
});
});
</script>
链接在这里
http://barrysfiles.co.uk/exp/development-bundle/demos/droppable/barrytest2.php
您可以从drop回调中使用ui.dragable访问Dragged elment。
示例:http://jsfiddle.net/TfmZt/