Open jQuery accordion panel with link (outside of acccordion)

我与影子孤独终老i 提交于 2019-12-08 00:25:55

问题


Still new to jQuery!

I have an accordion that was built with the jQuery UI 1.10.1. It's pretty basic; the first item is showing by default, and the others are hidden until clicked on. I'd like to use links that exist above a jQuery accordion to open a certain accordion panel when clicked. It looks something like this:

Link1 Link2 Link3

| Accordion Header 1 |

| Accordion content 1 showing|

| Accordion Header 2 |

| Accordion content 2 hidden |

| Accordion Header 3 |

| Accordion content 3 hidden |

..so that when you click on "Link2", it hides Accordion content 1 and shows Accordion content 2.

I've searched the site and none of the answers seemed fitting.

Thanks


回答1:


You could probably use a different method for linking the button to the header sections, I just used the id from the button.

But essentially:

$( "#accordion" ).accordion();

$('.section-button').on('click', function(){
  var header = $('#accordion').find('.' + this.id);
  header.click();
});

Demo here




回答2:


As of Jul 1st 2018, if you run into this you can do:

$('#accordion').accordion({active:0})

Replace the 0 with the index of the tab. 0 will open the first, 1 the next etc..



来源:https://stackoverflow.com/questions/14991602/open-jquery-accordion-panel-with-link-outside-of-acccordion

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