dongtou9934 2015-10-01 21:30
浏览 69
已采纳

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

I have two div section were I'm performing drag/drop and sortable operations i have list of 5 draggable records in my draggable section I want to disable the draggable record as soon as I drop in droppable section to avoid duplicate records placed in droppable div section

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条回答 默认 最新

  • douye2572 2015-10-01 21:34
    关注

    In your drop function do this:

    ui.draggable.draggable( 'disable' );
    

    Here is a fiddle for you based on your code: http://jsfiddle.net/j6dqk54p/1/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部