[英]How to set default tab on page load using jquery?
How can I modify the script to have second tab (instead of first) as default when the page loads? 页面加载时,如何修改脚本以将第二个选项卡(而不是第一个)作为默认选项卡? Thanks..
谢谢..
<script>
$(function() {
$("#nav ul").tabs("#panes > div", {effect: 'fade', fadeOutSpeed: 400});
});
</script>
<!-- tab panes -->
<div id="panes">
<div>
<p>content1</p>
</div>
<div>
<p>content2</p>
</div>
</div>
<!-- navigator -->
<div id="nav">
<ul>
<li>
<a href="#1">
Tab1
</a>
</li>
<li>
<a href="#2">
Tab2
</a>
</li>
</ul>
</div>
Change your tabs to reflect the following 更改标签以反映以下内容
$(function() {
$("#nav ul").tabs("#panes > div", {initialIndex: 1, effect: 'fade', fadeOutSpeed: 400});
});
EDIT: 编辑:
It looks as though your real question pertains to jQuery Tools rather than jQuery UI, as per your example you provided. 根据您提供的示例,您似乎真正的问题与jQuery工具有关,而不是与jQuery UI有关。 I have therefore updated my code to match the jQuery Tools documentation found here .
因此,我已经更新了代码以匹配此处找到的jQuery Tools文档。 The issue is, jQuery UI uses something called
selected
to determine the zero-indexed initial tab shown. 问题是,jQuery UI的使用一些所谓的
selected
,以确定出零索引初始选项卡。 jQuery Tools by contrast uses something called initialIndex
. 相比之下,jQuery Tools使用称为
initialIndex
东西。 You can find a working example of your code here . 您可以在此处找到代码的有效示例。
Use the selected option. 使用所选的选项。
<script>
$(function() {
$("#nav ul").tabs("#panes > div", {effect: 'fade', fadeOutSpeed: 400, selected:1});
});
</script>
Check the URL: 检查URL:
http://docs.jquery.com/UI/Tabs#options
http://docs.jquery.com/UI/Tabs#options
Just add `ui-tabs-selected to your second Tab. 只需将`ui-tabs-selected添加到第二个Tab。
<div id="nav">
<ul>
<li>
<a href="#1">
Tab1
</a>
</li>
<li class="ui-tabs-selected">
<a href="#2">
Tab2
</a>
</li>
</ul>
But you have to do some additional css styling 但是你必须做一些额外的CSS样式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.