启用禁用 jquery 选项卡
我有一个 jquery 选项卡容器,其中有两个选项卡。现在我想要的是最初第二个选项卡将被禁用。单击第一个选项卡上的按钮后,第二个选项卡将启用并自动打开。
<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>
I have a jquery tab container, in which there are two tabs. Now what I want is initially second tab will be disabled. On clicking a button on the first tab second tab will be enabled and open automatically.
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用以下内容
并使用零索引数字来选择禁用哪些。要启用选项卡,您可以使用以下命令:
要设置所选选项卡,您可以使用 中的示例jQuery 选项卡:
You can use the following
And use the zero-indexed numbers to choose which are disabled. To enable your tabs you can use this:
For setting the selected tab, you can use this example from jQuery Tabs:
我会默认禁用所有这些,然后启用第一个。之后,按钮应该非常简单。所有这些都应该非常简单。
首先:jQuerys
tabs('disable')
不起作用。所以我构建了自己的函数来禁用它们。就是这样:您可以像这样使用它:
disableTabs($('#myTabs'))
。 jQuery 不允许您禁用当前选项卡 - 由于这是在页面加载时进行的,因此它将是第一个选项卡。然后,您需要创建一些变量来存储一些数据...然后,几个函数来处理它...
然后,我们只需附加一些事件处理程序:
这些按钮的 HTML 非常简单:
希望这会有所帮助 -祝你好运!
顺便说一句:我在此处上有一些完整的工作选项卡,您可能想查看。
I would disable all of them by default, and then enable the first one. After that, the button should be pretty simple. All of this should be pretty simple.
First: jQuerys
tabs('disable')
just doesn't work. So I built my own function to disable them all. Here that is:You can use it like this:
disableTabs($('#myTabs'))
. jQuery doesn't allow you to disable the current tab - and since this is going on page load, it's going to be the first one. Then, you will need to make some variables to store some data...Then, a couple of functions to handle it...
Then , we just attach some event handlers:
The HTML for those buttons is really simple:
Hope this helps - and good luck!
BTW: I have some full working tabs up here that you might want to look at.
我解决这个问题的方法是使用一个变量来跟踪按钮是否被单击,默认情况下将其设置为“false”,单击按钮时将其设置为“true”。
然后,在选项卡链接的单击事件中检查此变量的值将允许您决定是显示新选项卡、不执行任何操作,还是显示消息。
这是一个工作示例:http://jsbin.com/ijoco5
The way I would tackle this is to use a variable that tracks whether the button has been clicked, setting it to 'false' by default and 'true' when the button has clicked.
Checking the value of this variable within the click event of the tab links will then allow you to decide whether to show the new tab, do nothing, or perhaps show a message.
Here's a working example: http://jsbin.com/ijoco5
假设您单击的按钮不是内部选项卡类并希望打开第二个选项卡,那么您可以添加触发事件,例如:
并将 id 赋予 li > > a :
Assuming you are clicking a button which is not a inside tab class and want 2nd tab to open then you can add trigger event like :
And give id to li > a :
<a id="tab1" href="#tab1"></a>