简体   繁体   English

使用来自同一网站上其他页面的超链接定位特定的选项卡

[英]Target specific tab with hyperlink from other page on same website

I've got a page (documents.php) that contains four tabs, the 1st tab is set as the default and opens when one browses to documents.php 我有一个页面(documents.php),其中包含四个选项卡,第一个选项卡设置为默认选项卡,当其中一个浏览到documents.php时打开

I need to be able to target tabs 2, 3 and 4 directly from hyperlinks on my index.php and a JavaScript menu that appears on all pages on the site. 我需要能够直接通过index.php上的超链接以及出现在网站所有页面上的JavaScript菜单来定位选项卡2、3和4。

Example: 例:

Tab 3 on documents.php contains "archived documents". documents.php上的选项卡3包含“存档文档”。

On Index.php I want to place a link called "Click here to go to Archived documents" and when someone clicks on it it must take them to documents.php but automatically go to Tab 3 which is "archived documents" and not go to the default 1st Tab. 在Index.php上,我想放置一个名为“单击此处转到存档的文档”的链接,当有人单击它时,必须将其带到documents.php,但是自动转到选项卡3,即“存档的文档”,而不是转到默认的第一个标签。

Here is the coding I am using to create the Tabs and would like to only modify this at most (and not re-invent the wheel by using jQuery or other technology and re-write the tabs on this and other pages): 这是我用来创建选项卡的编码,并且只想最多对其进行修改(而不是通过使用jQuery或其他技术重新发明轮子,而是在此页面和其他页面上重写选项卡):

HTML: 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: 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>

Then there's some CSS in an external style sheet that formats the Tabs, their borders, background etc. 然后在外部样式表中有一些CSS,用于格式化Tab,其边框,背景等。

CSS Formatting: 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;
}

Pass the # value url like http://example.com#tabs3 .Then use like this in your document ready. 传递#值网址,例如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;
  });

});

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

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