jQuery选项卡选择 [英] jquery tabs selection
本文介绍了jQuery选项卡选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
jquery代码是这样的:
the jquery code is like this:
$(document).ready(function() {
//When page loads...
$(".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 href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
});
和标签:
<ul class="tabs">
<li><a href="#tab1">Gallery</a></li>
<li><a href="#tab2">Submit</a></li>
</ul>
<div class="tab_container">
<div id="tab1" class="tab_content">
<!--Content-->
</div>
<div id="tab2" class="tab_content">
<!--Content-->
</div>
</div>
页面加载时,第一个标签页都会首先打开.但是,如果我想显示第二个选项卡,那我该怎么做.就像从函数内部 我正在加载页面,例如:window.location ="display.php"; 加载时,我希望第二个标签页打开该怎么做?如果我希望第一个选项卡显示如何执行此操作,还可以从另一个功能获取?
whenever the page loads the 1st tab is opened 1st. but if i want the 2nd tab to show, then how can i do that. like from inside a function im loading the page like: window.location="display.php"; when loaded i want the 2nd tab to open how to do that?? also from another function if i want the 1st tab to show how to do that?
先谢谢了.
推荐答案
做到这一点,
$(document).ready(function() {
//When page loads...
$(".tab_content").hide(); //Hide all content
var index = $("ul.tabs li.active").show().index();
$(".tab_content").eq(index).show();
//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 href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
});
然后在html的标签(li
)上,设置一个活动图标,
then on the tabs (li
) on the html, set an active like,
<ul class="tabs">
<li class="active"><a href="#tab1">Gallery</a></li>
<li><a href="#tab2">Submit</a></li>
</ul>
<div class="tab_container">
<div id="tab1" class="tab_content">
<!--Content-->
</div>
<div id="tab2" class="tab_content">
<!--Content-->
</div>
</div>
这篇关于jQuery选项卡选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文