jQuery UI 在禁用后重新启用新函数中的可拖动功能

发布于 2024-09-19 04:58:11 字数 2239 浏览 5 评论 0原文

我正在开发一个需要拖放的应用程序。放置后,选定的可拖动对象需要保持存在但会被禁用。然后,新的“已删除”项目会附加一个“关闭”按钮。单击关闭按钮后,该项目将从“可放置”区域消失并重新激活为可拖动。

问题是,一旦我禁用可拖动(成功放置后),我就无法在单独的“删除”功能中重新启用该唯一项目。这里有一些示例代码 - 为了简单起见,很多代码都被删除了,希望就我遇到的这个特定问题获得建议。

// DROP: initiate droppables  

    $(".droppable").droppable({
            hoverClass: 'drag-state-hover',
            accept: '.draggable li img',
            tolerance: 'fit',
            drop: function(event, ui) {

                var elementID = $(ui.draggable).attr("id") // get the dynamically set li id for each list item chosen

                if(    $(this).children('img').attr('src') == 'images/elements/blank.gif'  ) {

                    // disable the element once it's been dragged and dropped
                    $(ui.draggable).draggable( 'option', 'disabled', true );
                    // turn on the remove link
                    $(this).find('a.remove').toggle();                                       

                }                                                                          

            }                                                                               
        });       



    // ITEM REMOVE: function for removing items
    $('.remove').click(function(e) {

            var targetID = $(this).parent('li').attr('id');
            $('#' + targetID).children('img').draggable( 'option', 'disabled', false );

            e.preventDefault();

        });

我也尝试过这个,但没有成功......

// ITEM REMOVE: function for removing items
$('.remove').click(function(e) {

        var targetID = $(this).parent('li').attr('id');

        $(".droppable").droppable({
            hoverClass: 'drag-state-hover',
            accept: '.draggable li img',
            tolerance: 'fit',
            drop: function(event, ui) {                           
                $(ui.draggable).draggable( 'option', 'disabled', false );                                                   
            }                                                                               
        });                                                               

        e.preventDefault();

    });

我花了几天时间在谷歌上搜索解决方案,但此时我正在碰头。任何帮助将不胜感激。谢谢!!

I'm working on an app that requires drag-drop. Upon drop, the selected draggable needs to remain present but become disabled. Then the new 'dropped' item is appended with a 'close' button. Upon clicking the close button, the item disappears from the 'droppable' area and re-activates as a draggable.

The issue is that once I disable the draggable (after successful drop), i cannot re-enable that one unique item in my separate 'remove' function. here's some sample code - alot of it is stripped out for purposes of simplicity in hopes of getting advice on this particular issues i'm having.

// DROP: initiate droppables  

    $(".droppable").droppable({
            hoverClass: 'drag-state-hover',
            accept: '.draggable li img',
            tolerance: 'fit',
            drop: function(event, ui) {

                var elementID = $(ui.draggable).attr("id") // get the dynamically set li id for each list item chosen

                if(    $(this).children('img').attr('src') == 'images/elements/blank.gif'  ) {

                    // disable the element once it's been dragged and dropped
                    $(ui.draggable).draggable( 'option', 'disabled', true );
                    // turn on the remove link
                    $(this).find('a.remove').toggle();                                       

                }                                                                          

            }                                                                               
        });       



    // ITEM REMOVE: function for removing items
    $('.remove').click(function(e) {

            var targetID = $(this).parent('li').attr('id');
            $('#' + targetID).children('img').draggable( 'option', 'disabled', false );

            e.preventDefault();

        });

I've also tried this with no success...

// ITEM REMOVE: function for removing items
$('.remove').click(function(e) {

        var targetID = $(this).parent('li').attr('id');

        $(".droppable").droppable({
            hoverClass: 'drag-state-hover',
            accept: '.draggable li img',
            tolerance: 'fit',
            drop: function(event, ui) {                           
                $(ui.draggable).draggable( 'option', 'disabled', false );                                                   
            }                                                                               
        });                                                               

        e.preventDefault();

    });

I've spent days searching on google for a solution, but I'm banging my head at this point. any assistance would be much appreciated. Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吝吻 2024-09-26 04:58:11

您可以使用 .draggable( 'enable' ); ,而不是使用 .draggable( 'option', 'disabled', false ); 。我不知道这是否能解决您的问题,但这就是我开始调试它的方式。

Rather than using .draggable( 'option', 'disabled', false ); you can use .draggable( 'enable' );. I don't know if that will solve your problem, but that's how I'd start with debugging it.

吾家有女初长成 2024-09-26 04:58:11

在您的删除功能中,您是否尝试过将元素重新实例化为可拖动元素? $('#' + targetID).children('img').draggable{}

In your remove function, have you tried to re-instantiate the element as a draggable? $('#' + targetID).children('img').draggable{}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文