我有一个由5个标签组成的标签结构。所有标签都运行正常。现在在我的第一个标签中,我有几个标题标签与其他4个标签相同。因此,当点击它们时,我想要更改活动选项卡以及内容。我的代码如下。
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<ul class="nav nav-pills" id="myTab">
<li class="active"><a data-toggle="tab" href="#overview">Overview</a>
</li>
<li><a data-toggle="tab" href="#tab1">tab1</a>
</li>
<li><a data-toggle="tab" href="#tab2">tab2</a>
</li>
<li><a data-toggle="tab" href="#tab3">tab3</a>
</li>
<li><a data-toggle="tab" href="#tab4">tab4</a>
</li>
</ul>
<div class="tab-content">
<div id="overview" class="tab-pane fade in active">
<p>overview</p>
<br>
<a href="#tab1">
<h3>tab1 link</h3>
</a>
<br>
<a href="#tab2">
<h3>tab2 link</h3>
</a>
<br>
<a href="#tab3">
<h3>tab3 link</h3>
</a>
<br>
<a href="#tab4">
<h3>tab4 link</h3>
</a>
</div>
<div id="tab1" class="tab-pane fade">
<p>Vestibulum nec erat eu nulla rhoncus fringilla ut non neque. Vivamus nibh urna, ornare id gravida ut, mollis a magna. Aliquam porttitor condimentum nisi, eu viverra ipsum porta ut. Nam hendrerit bibendum turpis, sed molestie mi fermentum id. Aenean
volutpat velit sem. Sed consequat ante in rutrum convallis. Nunc facilisis leo at faucibus adipiscing.</p>
</div>
<div id="tab2" class="tab-pane fade">
<p>WInteger convallis, nulla in sollicitudin placerat, ligula enim auctor lectus, in mollis diam dolor at lorem. Sed bibendum nibh sit amet dictum feugiat. Vivamus arcu sem, cursus a feugiat ut, iaculis at erat. Donec vehicula at ligula vitae venenatis.
Sed nunc nulla, vehicula non porttitor in, pharetra et dolor. Fusce nec velit velit. Pellentesque consectetur eros.</p>
</div>
<div id="tab3" class="tab-pane fade">
<p>Donec vel placerat quam, ut euismod risus. Sed a mi suscipit, elementum sem a, hendrerit velit. Donec at erat magna. Sed dignissim orci nec eleifend egestas. Donec eget mi consequat massa vestibulum laoreet. Mauris et ultrices nulla, malesuada volutpat
ante. Fusce ut orci lorem. Donec molestie libero in tempus imperdiet. Cum sociis natoque penatibus et magnis dis parturient.</p>
</div>
<div id="tab4" class="tab-pane fade">
<p>Donec vel placerat quam, ut euismod risus. Sed a mi suscipit, elementum sem a, hendrerit velit. Donec at erat magna. Sed dignissim orci nec eleifend egestas. Donec eget mi consequat massa vestibulum laoreet. Mauris et ultrices nulla, malesuada volutpat
ante. Fusce ut orci lorem. Donec molestie libero in tempus imperdiet. Cum sociis natoque penatibus et magnis dis parturient.</p>
</div>
</div>
&#13;
任何帮助很快就会有所帮助。
答案 0 :(得分:1)
您只需将内容放在tab-content
中即可使其正常工作。
这将像你想要的那样工作。试试吧:
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<ul class="nav nav-pills" id="myTab">
<li class="active"><a data-toggle="tab" href="#tab1">tab1</a>
</li>
<li><a data-toggle="tab" href="#tab2">tab2</a>
</li>
<li><a data-toggle="tab" href="#tab3">tab3</a>
</li>
<li><a data-toggle="tab" href="#tab4">tab4</a>
</li>
</ul>
<div id="myTabContent" class="tab-content">
<p>overview</p>
<br>
<div id="tab1" class="tab-pane fade in active">
<p>Vestibulum nec erat eu nulla rhoncus fringilla ut non neque. Vivamus nibh urna, ornare id gravida ut, mollis a magna. Aliquam porttitor condimentum nisi, eu viverra ipsum porta ut. Nam hendrerit bibendum turpis, sed molestie mi fermentum id. Aenean
volutpat velit sem. Sed consequat ante in rutrum convallis. Nunc facilisis leo at faucibus adipiscing.</p>
</div>
<div id = "tab2" class = "tab-pane fade">
<br>
<p>WInteger convallis, nulla in sollicitudin placerat, ligula enim auctor lectus, in mollis diam dolor at lorem. Sed bibendum nibh sit amet dictum feugiat. Vivamus arcu sem, cursus a feugiat ut, iaculis at erat. Donec vehicula at ligula vitae venenatis.
Sed nunc nulla, vehicula non porttitor in, pharetra et dolor. Fusce nec velit velit. Pellentesque consectetur eros.</p>
</div>
<br>
<div id="tab3" class="tab-pane fade">
<p>Donec vel placerat quam, ut euismod risus. Sed a mi suscipit, elementum sem a, hendrerit velit. Donec at erat magna. Sed dignissim orci nec eleifend egestas. Donec eget mi consequat massa vestibulum laoreet. Mauris et ultrices nulla, malesuada volutpat
ante. Fusce ut orci lorem. Donec molestie libero in tempus imperdiet. Cum sociis natoque penatibus et magnis dis parturient.</p>
</div>
<div id="tab4" class="tab-pane fade">
<p>Donec vel placerat quam, ut euismod risus. Sed a mi suscipit, elementum sem a, hendrerit velit. Donec at erat magna. Sed dignissim orci nec eleifend egestas. Donec eget mi consequat massa vestibulum laoreet. Mauris et ultrices nulla, malesuada volutpat
ante. Fusce ut orci lorem. Donec molestie libero in tempus imperdiet. Cum sociis natoque penatibus et magnis dis parturient.</p>
</div>
</div>
运行此codepen
答案 1 :(得分:1)
基于引导文档here
使用像这样的jquery函数
clock_t begin, end;
double time_spent;
begin = clock();
/* here, do your time-consuming job */
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
这将适用于您单击的任何链接,并将您带到其href设置为
的选项卡