繁体   English   中英

将jQuery手风琴元素从一种手风琴移到另一种

[英]Moving jquery accordion elements from one accordion to another

这有点奇怪。 我有两个jquery手风琴实体,在一个手风琴中单击某个项目时,我想将其动态添加到第二个手风琴中,并将其隐藏在原始手风琴中。

当前从A移到B的效果很好,在从B移回A的过程中,但是当我将一件物品移回原始手风琴时,随后从A移到B的任何动作都会加速。

这是我的意思的jsfiddle示例http://jsfiddle.net/waveydavey/CAYth/ 注意,我完全意识到代码很丑陋-我只是在学习这些东西。 请随意提出更好的方法十倍。 请执行下列操作:

  • 运行小提琴。
  • 单击每个项目的“ +”移至手风琴2
  • 一切都很好。

现在执行以下操作:

  • 运行小提琴。
  • 单击任何“ +”移至第二手风琴
  • 在移动的项目上单击“ x”,它会重新出现在第一组中
  • 单击任何“ +”项以添加到第二组
  • 显示屏完全弄乱了手风琴项目

任何建议将不胜感激。

jsfiddle代码是:

    $(function() {
 // create accordion entities
 $('#avAccordion').accordion({
        collapsible: true,
        autoHeight: false,
        active: false
    });
 $('#assignedAccordion').accordion({
        collapsible: true,
        autoHeight: false,
        active: false
    });
 $('.accordionAdd').click(function(){
        // destroy the accordion, prior to rebuilding
        $('#avAccordion').accordion('destroy');
        // get the h3 part and tweak it's contents
        var h3bit = $(this).parent().clone();
        $(h3bit).removeClass('freeContacts').addClass('assignedContacts');
        $(h3bit).children('span').removeClass('ui-icon-circle-plus accordionAdd').addClass('ui-icon-circle-close accordionDel');
        // get the div part after the h3
        var divbit = $(this).parent().next().clone();
        // rebuild original accordion
        $( "#avAccordion" ).accordion({
            collapsible: true,
            autoHeight: false,
            active: false
        });
        // move contents to other accordion
     $('#assignedAccordion').append(h3bit)
         .append(divbit)
         .accordion('destroy')
         .accordion({
            collapsible: true,
            autoHeight: false,
            active: false
        });
        // hide original accordion entry
        $(this).parent().hide();
        //attach click handler to new item
        $('.accordionDel').click(function(){
            dropAssignedContact(this);
            return false;
        })
        return false;
    });

    function dropAssignedContact(obj){
        // unhide right hand object with appropriate data-id attr
        var id = $(obj).parent().attr('data-id');
       // delete myself
        $(obj).parent().remove();
        // unhide original
        $('.freeContacts[data-id='+id+']').show();
        $('#assignedAccordion').accordion('destroy').accordion({
            collapsible: true,
            autoHeight: false,
            active: false
        });
    }
});

看到这个更新的小提琴: http : //jsfiddle.net/KTWEd/

function dropAssignedContact(obj){
    // unhide right hand object with appropriate data-id attr
    var id = $(obj).parent().attr('data-id'); 

   // delete myself
    $(obj).parent().next().remove();   // <---   Removes the adjacent div
    $(obj).parent().remove();

    // unhide original
    $('.freeContacts[data-id='+id+']').show();
    $('#assignedAccordion').accordion('destroy').accordion({
        collapsible: true,
        autoHeight: false,
        active: false
    });
 }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM