【问题标题】:Disable draggable JQuery UI once it dropped in Droppable section一旦拖放到 Droppable 部分就禁用可拖动的 JQuery UI
【发布时间】:2015-12-30 07:16:54
【问题描述】:

我有两个 div 部分,我正在执行拖放和可排序操作 我的可拖动部分中有 5 个可拖动记录的列表 我想在放入可放置部分后立即禁用可拖动记录以避免放置重复记录在可放置的 div 部分中

HTML 代码

<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 代码

 $(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
            });
    });

【问题讨论】:

  • 你能做一个小提琴吗?

标签: javascript php jquery html jquery-ui


【解决方案1】:

在你的 drop 函数中这样做:

ui.draggable.draggable( 'disable' );

这是根据您的代码为您准备的小提琴:http://jsfiddle.net/j6dqk54p/1/

【讨论】:

  • 如果解决了 OP 的问题,为什么有人投反对票?
  • 我真的很抱歉我是初学者,我不知道发生了什么事情,你的回答是当场满足我的要求。我接受了你的回答并投了赞成票,我不明白出了什么问题,但感谢 tonnnnnn 帮助我,我将把它推送到堆栈溢出以了解它。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-27
  • 1970-01-01
  • 2013-06-22
  • 1970-01-01
  • 2011-04-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多