【问题标题】:jquery ui drag and drop - call function on dropjquery ui拖放-拖放时调用函数
【发布时间】:2016-03-17 10:48:00
【问题描述】:

我希望 alert('dropped'); 在我将项目放入 div 时执行。 drop 事件处理程序似乎不起作用。

$('.dropme').sortable({
    connectWith: '.dropme',
    cursor: 'pointer'
}).droppable({
    accept: '.button',
    activeClass: 'highlight',
    drop: function(event, ui) {
        var $li = $('<div>').html('List ' + ui.draggable.html());
        $li.appendTo(this);
        alert('dropped');
    }
});

这是一个小提琴的链接:http://jsfiddle.net/8snSf/2195/

建议一如既往。

【问题讨论】:

    标签: jquery jquery-ui drag-and-drop


    【解决方案1】:

    问题是因为sortable() 插件启用了拖放行为。因此,您需要使用该插件的stop 处理程序,而不是draggable()drop。试试这个:

    $('.dropme').sortable({
        connectWith: '.dropme',
        cursor: 'pointer',
        stop: function(event, ui) {
            var $li = $('<div>').html('List ' + ui.item.html());
            $li.appendTo(this);
            alert('dropped');
        }
    });
    

    Updated fiddle

    【讨论】:

    • 非常感谢,
    • 没问题,很高兴为您提供帮助
    猜你喜欢
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    • 2010-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-21
    相关资源
    最近更新 更多