Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 引导选项卡问题_Html_Css_Twitter Bootstrap - Fatal编程技术网

Html 引导选项卡问题

Html 引导选项卡问题,html,css,twitter-bootstrap,Html,Css,Twitter Bootstrap,我有一个带有选项卡导航的html页面,名为B.html。我在我的html页面中设置了选项卡,如下所示 <div class="tabbable"> <ul class="nav nav-tabs"> <li class="active"><a href="#tab1" data-toggle="tab">Section 1</a></li> <li><a href="#tab2" dat

我有一个带有选项卡导航的html页面,名为B.html。我在我的html页面中设置了选项卡,如下所示

<div class="tabbable">
  <ul class="nav nav-tabs">
    <li class="active"><a href="#tab1" data-toggle="tab">Section 1</a></li>
    <li><a href="#tab2" data-toggle="tab">Section 2</a></li>
  </ul>
  <div class="tab-content">
    <div class="tab-pane active" id="tab1">
      <p>I'm in Section 1.</p>
    </div>
    <div class="tab-pane" id="tab2">
      <p>Howdy, I'm in Section 2.</p>
    </div>
  </div>
</div>
<a href="http://www.abc.com/B.html#tab1">T1</a>
<a href="http://www.abc.com/B.html#tab2">T2</a>

但这并不奏效。它总是选择tab1。如何解决此问题?

您可以使用javascript/jquery来解决此问题,读取哈希值并打开所需的选项卡:

标记:

<div class="tabbable">
  <ul class="nav nav-tabs" id='my_tab'>
    <li class="active"><a href="#tab1" data-toggle="tab">Section 1</a></li>
    <li><a href="#tab2" data-toggle="tab">Section 2</a></li>
  </ul>
  <div class="tab-content">
    <div class="tab-pane active" id="tab1">
      <p>I'm in Section 1.</p>
    </div>
    <div class="tab-pane" id="tab2">
      <p>Howdy, I'm in Section 2.</p>
    </div>
  </div>
</div>

以上是非常通用的代码,可以根据您的需要进行优化。

什么是
#myTab
中的
$('#myTab a:first')。tab('show')?我想应该是
my_选项卡
。更正它,我将接受你的答案作为正确答案。此滚动页面指向选项卡在html页面中的位置。它隐藏页面标题。我可以避免吗?我可以正常加载页面而不滚动到制表符位置吗?我没有得到这个:它隐藏页面标题。你们有固定的标题吗?若有20个标签,你们会怎么做?或者一个动态变化的标签数量?我想你可以试试:window.scrollTo(0);
    var tabs = $("#my_tab");
    if (window.location.hash === '#tab1') {
        $('#my_tab a:first').tab('show');     
    }
    else if(window.location.hash === '#tab2') {
        $('#my_tab a:last').tab('show');     
    }