2

当我单击可拖动的 div 时,场景中的一些 div 变为可放置的,当我将元素拖动到其目的地时,可放置的 div 被禁用。它工作正常,但是当我想再次删除另一个元素时,我无法启用相同的 div。我该如何启用它? http://jsfiddle.net/6v8Lc/3/

function drop (childSocket, inputCache) {
//when "on mousedown" for pawn, pawnSocket calculated if its suitable droppable or not
$(".pawnSocket:nth-child("+childSocket+")").droppable({
    hoverClass: "over",
    drop: function(ev, ui) {
        var thisPosLeft = $(this).position().left;
        var thisPosTop = $(this).position().top;
        var draggedPawn = $(ui.draggable);
        draggedPawn.css({
            left: thisPosLeft,
            top: thisPosTop
        });
        var thisIndex = $(this).index();
        var suruklenenIndex = piyonYuvaKonum.indexOf(inputCache);
        piyonYuvaKonum[suruklenenIndex] = null;
        piyonYuvaKonum[thisIndex] = inputCache;

        // when i run disable option, it becomes disabled but i can't enable again


        $(".pawnSocket").droppable("disable");
        //$(this).droppable("option", "disabled", true);
    }
});
}
4

1 回答 1

1

与其在每次拖动时重新声明可放置的项目,不如将它们声明为可放置并在您希望它们禁用或启用时设置它们。

$(".drag").draggable({ revert: "invalid"})
    .on("mousedown", function () {
        $(".drop").droppable('enable');

});
$(".drop").droppable({
        hoverClass: "over",
        drop: function (ev, ui) {
            var dizPozL = $(this).position().left + 5;
            var dizPozT = $(this).position().top + 5;
            var suruklenenPiyon = $(ui.draggable);
            suruklenenPiyon.css({
                left: dizPozL,
                top: dizPozT
            });
            suruklenenPiyon.hide("slow");
            $(".drop").droppable("disable");
        },
        disabled:true
    });
于 2013-05-23T17:03:47.577 回答