0

我无法从用作拖放框的框中获取值。框拖放正确加上我可以用一个值更新一个 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

4

1 回答 1

0

您可以从 drop 回调中使用 ui.draggable 访问 Dragged 元素。

示例:http: //jsfiddle.net/TfmZt/

于 2012-08-25T10:41:05.683 回答