根据页面/文件名激活

时间:2013-05-08 16:53:25

标签: php jquery accordion

在我的项目中有一个菜单H2 如果我点击任何菜单名称H2然后它打开并显示子菜单。现在默认情况下它是第一个 (管理机构) open..so当我点击任何链接,如添加图库时,它会转到该页面并且< strong>图库管理将开放(活动),其余部分将关闭。现在总是打开第一个 (管理机构) ..

我怎么能这样做。任何的想法。 Jquery或php没问题。我只是让它发挥作用......

请查看此http://jsfiddle.net/KM4w6/

$(document).ready(function(){


//sub menu  
//Set default open/close settings
$('.acc_container').hide(); //Hide/close all containers
//$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

//On Click
$('.acc_trigger').click(function(){
    if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
        $('.acc_trigger').removeClass('active').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
        $(this).toggleClass('active').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
    }
    return false; //Prevent the browser jump to the link anchor
});

}); 




 <div class="navarea">
  <h2 class="acc_trigger">Governing Body</h2>
  <div class="acc_container">
    <ul>
      <li><a href="new_position.php">Add Position</a></li>
      <li><a href="list_position.php">Edit/Delete Position</a></li>
      <li><a href="new_member.php">Add Member</a></li>
      <li><a href="list_member.php">Edit/Delete Member</a></li>
    </ul>
  </div>
  <h2 class="acc_trigger">Gallery Managment</h2>
  <div class="acc_container">
    <ul>
      <li><a href="new_gallery_info.php">Add Gallery</a></li>
      <li><a href="list_gallery_info.php">Edit/Delete Gallery</a></li>
      <li><a href="list_gallery_images.php">Gallery Images Management</a></li>
    </ul>
  </div>

   <h2 class="acc_trigger">Other</h2>
   <div class="acc_container">
  <ul>
    <li><a href="cms.php?page='about_us'">About Us</a></li>
    <li><a href="new_link.php">Add Link</a></li>
    <li><a href="list_link.php">Edit/Delete Link</a></li>
    <li><a href="new_event.php">Add Event</a></li>
    <li><a href="list_event.php">Edit/Delete Event</a></li>
  </ul>
  </div>
</div>

2 个答案:

答案 0 :(得分:1)

假设您有一个不同的页面/网址可供检测,您可以执行以下操作:

if(window.location.indexOf('_gallery')>0){
   $('.acc_trigger:contains("Gallery Managment")').click();
} else if(window.location.indexOf('_position')>0 || window.location.indexOf('_member')>0){
   $('.acc_trigger:contains("Governing Body")').click();
}

Edited fiddle

答案 1 :(得分:0)

它是这样的。我检查了。这是正确的做法......或者有其他好办法。

if( location.href.match("new_gallery_info.php") ){
   $('.acc_trigger:contains("Gallery Managment")').click();

}