EasyUI - How to add a new Item of Accordion on the top?

北城以北 提交于 2019-12-06 15:35:25

问题


I'm having an application using jquery-easyui using an Accordion on the Web page.

The HTML Code of Accordion is:

<div id="taskAccordion" class="easyui-accordion" data-options="multiple:false" style="width:500px; height:300px;">
    <div title="Java" style="padding:10px;">
        <p>This is Java.</p>
    </div>
    <div title="PHP" style="padding:10px;">
        <p>This is PHP.</p>
    </div>
    <div title="JS" style="padding:10px;">
        <p>This is JS.</p>
    </div>
</div>

I want ao add a new Item into Accordion with JS in runtime. The JS-function for adding is:

function addItem(){
    $('#taskAccordion').accordion('add',{
        title: 'Perl',
        selected: false,
        content:'This is Perl.'
    });
}              

The question is:
The new Item is under the Item "JS".
How can I add the Item on the top as the first one? Before the "Java"

Thank you!


回答1:


You can change the position of the item immediately after it is added. The following function moves the last element to the beginning of the accordion. In case you want to move the element to a different position you simply need to specify ids to the existing elements and then modify the selector accordingly.

function addItem(){
    $('#taskAccordion').accordion('add',{
        title: 'Perl',
        selected: false,
        content:'This is Perl.'
    });
    $('#taskAccordion').prepend($("#taskAccordion").children().last());
}  



回答2:


1.delete old panels 2.add new panel 3.add old panels

But, the solution is foolish. hh



来源:https://stackoverflow.com/questions/30864178/easyui-how-to-add-a-new-item-of-accordion-on-the-top

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!