我有一个 jquery选项卡容器,其中有两个选项卡.现在我想要的是最初第二个选项卡将被禁用.单击第一个选项卡上的按钮时,将启用第二个选项卡并自动打开. script type="text/javascript" $(docume
<script type="text/javascript">
$(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;
});
});
</script>
<div class="tab-wrapper" id="tab-wrapper">
<div class="tab-header">
<ul class="tabs">
<li><a href="#tab1">overview</a></li>
<li><a href="#tab2">details</a></li>
</ul>
</div>
<div class="tab_container">
<div id="tab1" class="tab_content">
here is the list of the overview
</div>
<div id="tab2" class="tab_content">
Particular Details
</div>
</div>
</div>
我要解决这个问题的方法是使用一个变量来跟踪按钮是否被点击,默认情况下将其设置为“false”,单击按钮时设置为“true”.
在选项卡链接的单击事件中检查此变量的值将允许您决定是显示新选项卡,不执行任何操作,还是显示消息.
这是一个有效的例子:http://jsbin.com/ijoco5
