0

我有一个包含四个选项卡的页面(documents.php),第一个选项卡设置为默认选项,并在浏览到documents.php时打开

我需要能够直接从我的 index.php 上的超链接和网站上所有页面上显示的 JavaScript 菜单中定位选项卡 2、3 和 4。

例子:

documents.php 上的选项卡 3 包含“归档文档”。

在 Index.php 上,我想放置一个名为“单击此处转到存档文档”的链接,当有人单击它时,它必须将它们带到documents.php,但会自动转到“存档文档”选项卡 3,而不是转到默认的第一个选项卡。

这是我用来创建选项卡的编码,并且最多只想修改它(而不是通过使用 jQuery 或其他技术重新发明轮子并重新编写此页面和其他页面上的选项卡):

HTML:

<ul>
    <li class="current"><a href="#tab1">General Documents</a></li>
    <li><a href="#tab2">Circulars</a></li>
    <li><a href="#tab3">Newsletters</a></li>
    <li><a href="#tab4">Archived Documents</a></li>
</ul>

Javascript:

<script>
$(document).ready(function(){
 $(".tabs li").click(function() {
  $(this).parent().parent().find(".tab-content").hide();
  var selected_tab = $(this).find("a").attr("href");
  $(selected_tab).fadeIn();
  $(this).parent().find("li").removeClass('current');
  $(this).addClass("current");
   return false;
    });
});</script>

然后在外部样式表中有一些 CSS,用于格式化选项卡、它们的边框、背景等。

CSS 格式:

.tabs ul{
    list-style:none;
    display:block;
    margin:0px;
    padding:0px;
    z-index:99;
    position:relative;
}
.tabs li {
    float:left;
    display:block;
    border-top:#E5E5E5 1px solid;
    border-left:#E5E5E5 1px solid;
    border-right:#E5E5E5 1px solid;
    border-top-left-radius:4px;
    border-top-right-radius:4px;
    position:relative;
    z-index:999;    
    color: #444444;
    padding: 4px 8px 4px 8px;
    margin: 0px 6px 0px 0px;
    background: #e7e7e7 url(/assets/images/common/bg.png) repeat-x;
}

.tabs li:hover {

/*If you want hover effects on tabs put your css here*/

}
.tabs li a {
    display:block;
    color:#323234;
    outline:none;
}

.tabs li.current {
    border-bottom:#DD6E27 2px solid;
    outline:none;
}

.tab-content {
    display:none;
    clear:both;
    min-height: 120px;
    border-top-left-radius:0px;
    border-top-right-radius:4px;
    border-bottom-left-radius:4px;
    border-bottom-right-radius:4px;
    color:#444444;
      background:#fefefe url(/assets/images/common/bg.png) repeat-x;
    border: 1px solid #E5E5E5;
    overflow:hidden;
    padding:15px;
}

.tab-content:first-child {
    display: block;
}
4

1 回答 1

0

传递 # 值 url,如http://example.com#tabs3。然后在准备好的文档中使用这样的方法。

$(document).ready(function(){
  var hash = window.location.hash;
  $('#'+ hash).addClass("current");

 $(".tabs li").click(function() {
  $(this).parent().parent().find(".tab-content").hide();
  var selected_tab = $(this).find("a").attr("href");
  $(selected_tab).fadeIn();
  $(this).parent().find("li").removeClass('current');
  $(this).addClass("current");
  return false;
  });

});
于 2013-06-14T11:58:30.563 回答