Extending Jquery accordion to rows of a table

别说谁变了你拦得住时间么 提交于 2019-12-11 01:57:22

问题


I have a table with collapsible rows. Please check here

I just want to use the Jquery UI accordion as shown here

I am trying to apply accordion to the below structure :

<table>
    <tbody class="category">
        <tr><td>Category - 1</td></tr>
    </tbody>
    <tbody class="subcategory">
        <tr><td>Sub Cateogry 1.1</td></tr>
        <tr><td>Sub Cateogry 1.2</td></tr>
    </tbody>
    <tbody class="category">
       <tr><td>Category - 2</td></tr>
    </tbody>
    <tbody class="subcategory">
       <tr><td>Sub Cateogry 2.1</td></tr>
    </tbody>
</table>

I understand that ordered list is most suitable for this type of structure.But due to some restrictions, table needs to be used.

Please suggest.


回答1:


Use the header option of the accordion:

$(document).ready(function () {
    $('table').accordion({header: '.category' });
});

https://jsfiddle.net/c1j7xbkp/



来源:https://stackoverflow.com/questions/16046654/extending-jquery-accordion-to-rows-of-a-table

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