这是jquery
$(document).ready(function() {
//Default Action
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
return false;
});
});
好的,使用上层jquery(和CSS)创建流行的标签(实际上是两个标签块)..
HTML
//first block
<div>
<ul class="tabs">
<li><a href="#tab1">1</a></li>
<li><a href="#tab2">2</a></li>
</ul>
<div class="tab_container">
<div id="tab1" class="tab_content">Content 1</div>
<div id="tab2" class="tab_content">Content 2</div>
</div>
</div>
<div>Something images in between</div>
//second block
<div>
<ul class="tabs">
<li><a href="#tab3">3</a></li>
<li><a href="#tab4">4</a></li>
</ul>
<div class="tab_container">
<div id="tab3" class="tab_content">Content 3</div>
<div id="tab4" class="tab_content">Content 4</div>
</div>
</div>
加载页面时
点击第二个区块中的标签会关闭/影响第一个区块的内容。
如何显示两个块(以及第一个选项卡),以及块作为单独的ID运行?
感谢名单!
答案 0 :(得分:0)
试试这个http://jsfiddle.net/54fDF/
HTML
//first block
<div>
<ul class="tabs">
<li><a href="#tab1">1</a></li>
<li><a href="#tab2">2</a></li>
</ul>
<div class="tab_container">
<div id="tab1" class="tab_content">Content 1</div>
<div id="tab2" class="tab_content">Content 2</div>
</div>
</div>
<div>Something images in between</div>
//second block
<div>
<ul class="tabs">
<li><a href="#tab3">3</a></li>
<li><a href="#tab4">4</a></li>
</ul>
<div class="tab_container">
<div id="tab3" class="tab_content">Content 3</div>
<div id="tab4" class="tab_content">Content 4</div>
</div>
</div>
的Javascript
$(document).ready(function() {
//Default Action
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_container").find("div:first").show(); //Show first tab content
//On Click Event
$("ul.tabs li").click(function() {
var contId = $(this).find('a').attr('href');
var parent = $(contId).parent();
parent.find('.tab_content').hide();
$(contId).fadeIn();
});
});