在Droppable部分删除后,禁用可拖动的JQuery UI

时间:2015-10-02 05:30:20

标签: javascript php jquery html jquery-ui

我有两个div部分是我执行拖放操作和可排序操作我在可拖动部分中列出了5个可拖动记录我想在放入可放置部分时禁用可拖动记录以避免重复放置在可放置div部分的记录

HTML CODE

<div>
        <form method="post" action="">
            <ol style='list-style:decimal' id="qselected"></ol>
        </form>
    </div>
    <br/>
    <div>
        <ul id="qlist">
            <?php 
                for($i=1;$i<=5;$i++)
                {
                ?>  
                    <li id='article_<?php echo $i;?>' >
                        <div class="qitem" style='margin-bottom : 20px;border-bottom:1px solid #e7e7e7;'>
                        <span data-item="1" class="question">Value : <?php echo $i;?></span>
                        </div>
                    </li>
                <?php
                }
            ?>
        </ul>
    </div>

JQUERY CODE

 $(document).ready(function() {

        $("#qselected").disableSelection();

        $(".qitem").draggable({
            containment : "#container",
            tolerance:"pointer",
            helper : 'clone',
            refreshPositions: true ,
            revert : 'invalid',
            opacity:.4
        });

        $("#qselected, #qlist").droppable({
            revert:true,
            hoverClass : 'ui-state-highlight',
            greedy: true,
            refreshPositions: true,
            drop : function(ev, ui) {
                $(ui.draggable).clone().appendTo(this);
                if($(this)[0].id === "qselected")
                {
                    console.log($(this).closest("button").find('.hello'));
                    $(this).find('.hello').hide();
                    $(this).find('.btn').show();
                    return true;
                }


            },
        }).sortable({
                revert: true,
                refreshPositions: true ,
                helper : 'clone',
                cursor: "move",
                delay: 1,
                tolerance: 'pointer',
                revert: 50
            });
    });

1 个答案:

答案 0 :(得分:0)

在你的drop函数中执行以下操作:

ui.draggable.draggable( 'disable' );

根据您的代码,这是一个小提琴:http://jsfiddle.net/j6dqk54p/1/

相关问题