获取Jquery UI拖放框的名称和值

时间:2012-08-24 12:02:24

标签: jquery jquery-ui

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

1 个答案:

答案 0 :(得分:0)

您可以使用drop callback中的ui.draggable访问Dragged元素。

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