open accordion with external link

最后都变了- 提交于 2019-12-06 15:06:38
$('a.anchor_about').click(function(){

   $("#accordion").accordion("activate", '<?php echo $_GET['id']; ?>');

   return false;

});

I don't think $_GET['id'] in the accordion activate line is going to work as I guess you want something like this

$('a.anchor_about').click(function(){
   var sectionId = $(this).attr("href");
   $("#accordion").accordion("activate", sectionId);

   return false;

});

check if this works - if there are any errors let me know.

EDIT **

Also, I think to open accordion you need an index based value not a ID value like #someId (which works for tab for sure). The index is zero-based so that first section of accordion can be activated by passing a zero value, second with 1, and so on.

Give the menu items a name according to index

<div id="navmenu" style='z-index:9999;'>
    <ul>
        <li><a href="#" name="0">About</a></li>
        <li><a href="#" name="1">Results</a></li>
        <li><a href="#" name="2">Contact</a></li>
    </ul>
</div>

then activate the appropriate accordionitem with the index given in the menu items:

$("#navmenu ul").children("li").click(function()
{
    $("#accordion").accordion("activate", $(this).attr("name"));

    // ALSO POSSIBLE (name attribute not needed):
    // Only if the menu items are in the same order as the accordion items
    $("#accordion").accordion("activate", $(this).index());
});

Edit

I just figured your code is in a different file, so here's an option to minimize the change to your code. Seeing as you send a hash and GET the ID in a new page. The accordion needs an indexnumber, not an ID: Accordion Methods

<div id="navmenu" style='z-index:9999;'>
    <ul>
        <li><a href="#0">About</a></li>
        <li><a href="#1">Results</a></li>
        <li><a href="#2">Contact</a></li>
    </ul>
</div>
$('#accordion').accordion({"active": $(window.location.hash).index()});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!