只需拖动即可调用Droppable代码

时间:2012-05-18 15:18:49

标签: javascript jquery

我不知道为什么当我将项目拖到可放置区域时会触发以下警告?

$(".all").droppable({ 
    drop: function(event, ui) { 
       alert('should just fire when a item is dropped');
    }
}); 



$("li").draggable({
            connectToSortable : ".mySortable",
            helper : "clone",
            revert : "invalid",
            scroll: true,
            cursor: 'move'//,   
}
        });

这是被调用的调用堆栈中最远的行:

jQuery.event.dispatch.apply( eventHandle.elem, arguments ) :

包含在jquery-1.7.2.js

该行代码在:

之内
if ( !eventHandle ) {
            elemData.handle = eventHandle = function( e ) {
                // Discard the second event of a jQuery.event.trigger() and
                // when an event is called after a page has unloaded
                return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ?


jQuery.event.dispatch.apply( eventHandle.elem, arguments ) :

                    undefined;
            };

如果将此代码粘贴到小提琴 - jsfiddle.net/Xz3u2中,则应重新创建错误:

$(".all2").sortable({
            revert : true
        });
$(".all").droppable({ 
    drop: function(event, ui) { 
       alert('should just fire when a item is dropped');
    }
}); 

$(".all2").draggable({
            connectToSortable : ".all2",
});​

1 个答案:

答案 0 :(得分:0)

尝试这样:http://jsfiddle.net/Xz3u2/2/

$(".all2").sortable({
            revert : true
        }).draggable();
$(".all").droppable({
    accept: '.all2',
    drop: function(event, ui) {
       alert('should just fire when a item is dropped');
    }
});