简体   繁体   English

通过外部链接访问jQuery手风琴

[英]Access jquery accordion with an external link

I have used Jquery UI accordion in my page and it is working as expected. 我在页面中使用了Jquery UI手风琴,它按预期工作。

I need to open the accordion panel with an external link which is a drop-down. 我需要通过一个外部链接打开一个手风琴面板。 How can I access accordion even with the drop-down list menu. 即使使用下拉列表菜单,如何访问手风琴。

Here is what I have done so far 这是我到目前为止所做的

// JavaScript Document
$(document).ready(function () {

    //Add list menu
    $('.droplist > li').hover(function () {
        $(this).find('ul').toggle();
    });

    //Accordion
    $( "#accordion" ).accordion({
          collapsible: true,
          active: false,
          heightStyle: "content"
        });
});

DEMO DEMO

PS : HTML format can not be changed. PS :不能更改HTML格式。

As the HTML cannot be change, you can try this: 由于无法更改HTML,因此您可以尝试以下操作:

$('.droplist > li > ul > li').on('click', function(){
    index = $(this).index();
    $( "#accordion" ).accordion( "option", "active", index );
});

Demo 演示

Reference 参考

.index() 。指数()

accordion - option 手风琴-选项

I may be mis-understanding the problem, but to me you are asking how to automatically open the first accordion item? 我可能对这个问题有误解,但是对我来说,您是在问如何自动打开第一个手风琴项目?

$('#accordion li a').first().trigger('click');

This will trigger the first accordion item to open. 这将触发第一个手风琴项目打开。

DEMO DEMO

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

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