【问题标题】:Jquery draggable disable list item after being dropped in other div被拖放到其他 div 后,Jquery 可拖动禁用列表项
【发布时间】:2016-01-22 05:04:59
【问题描述】:

我希望如果任何列表项 (li) 从产品 div 中拖放到购物车 div 中,该 li 将被禁用并且用户无法再次将其添加到购物车 div 中。

jQuery("#product li").draggable({
    appendTo: "body",
    helper: "clone"
});

jQuery("#cart ol").droppable({
    activeClass: "ui-state-default",
    hoverClass: "ui-state-hover",
    accept: ":not(.ui-sortable-helper)",
    drop: function (event, ui) {
        $(this).find(".placeholder").remove();
        $("<li></li>").text(ui.draggable.text()).appendTo(this);
    }
});

【问题讨论】:

    标签: jquery draggable droppable


    【解决方案1】:

    您可以禁用可拖动属性 As

    $( "#cart li").draggable({disabled:true});
    

    【讨论】:

    • 我只是想禁用那个特定的 li 而不是所有的项目?
    • @user3243439 Fort 你需要展示你的代码......如何在不知道 DOM 位置的情况下编写你的选择器
    • 购物车 div id 是什么??
    • 试试上面的编辑...只要告诉我它是否给出像cannot disable the property before applying to it 这样的错误
    【解决方案2】:

    在你的 drop 函数中添加:

    ul.dragged.draggable({disabled:true});
    

    【讨论】: