jQuery Drop事件无效

时间:2011-09-24 06:08:40

标签: jquery droppable

我在这里面临一个奇怪的问题。我已经有一个简单的jquery drag-n-drop试用版,它可以工作。但是,现在我想将代码从试用项目移动到我现在正在工作的项目文件中。一切都是相同的,但我不能让drop事件被解雇。真的很紧急,请帮忙...... 我包含了我的代码,以防万一...

  $('.image').draggable({
            cursor: 'move'
        });

        // Put img resizable is to have the ghost
        $('.image img').resizable({
            ghost: true,
            stop: function (event, ui) {
                var eid = $(this).parent().attr('id');
                alert(eid);
                var wid = $(this).width();
                alert(wid);
                var hei = $(this).height();
                alert(hei);
                updateSize(eid, wid, hei);
            }
        });

        // Variable to hold drop options
        var options = {};

        // Once image re-drop, update its position
        options.drop = function (event, ui) {
            // Check image id to check whether image exist or not
            if (ui.draggable.attr('id').match(/_(\d+)$/) != null) {
                var element = ui.draggable;
                updatePosition(element);
            }
            else {

                // Store the clone position
                var leftPosition = ui.offset.left;
                var topPosition = ui.offset.top;
                alert('Left: ' + leftPosition + ' Top: ' + topPosition);

                // Variable to generate new image id
                var counter = new Date().valueOf();

                // Create the clone
                //var element = ui.draggable.clone();

                // Assign new id for clone element
                var oldID = ui.draggable.attr('id');
                alert('old id ' + oldID);
                ui.draggable.attr('id', (oldID + '_' + counter));

                // Call CreateContainer
                createContainer(ui.draggable, oldID, topPosition, leftPosition);
            }
        };
        $('#rightframe').droppable(options);

1 个答案:

答案 0 :(得分:0)

似乎工作正常:

http://jsfiddle.net/DrUKa/