jquery 选项卡嵌套选项卡的问题,第一个选项卡无法加载
我在嵌套选项卡时遇到问题。当我单击选项卡 2 时,我需要默认显示嵌套 1。相反,它只是显示一个空白选项卡,直到我单击 Nested 2 并单击返回 Nested 1。
如果可能的话,我希望能够通过向 Ready 函数添加一些内容来解决此问题,因为更改实际的 .js 文件很痛苦。 ..提前致谢!
HTML:
<!--Begin Tabs-->
<div id="tab-container1">
<ul class="tabs">
<li><a href="#tab-1">Tab 1</a></li>
<li><a href="#tab-2">Tab 2</a></li>
<li><a href="#tab-3" rel="external-4.html">Tab 3</a></li>
</ul>
<div class="tab-panel">
<div id="tab-1">Tab 1 Content</div>
<div id="tab-2">
<!--BEGIN NESTED TABS-->
<div class="tab-carousel">
<div id="tab1-N">
<ul id="ul-N" class="tabs-nested">
<li><a href="#tab1-a" rel="external-1.html">Nested 1</a></li>
<li><a href="#tab1-b" rel="external-2.html">Nested 2</a></li>
<li><a href="#tab1-c" rel="external-3.html">Nested 3</a></li>
</ul>
<div class="tab-panel-nested">
<div id="tab1-a">Nested Tab One Content</div>
<div id="tab1-b">Nested Tab Two Content</div>
<div id="tab1-c">Nested Tab Three Content</div>
</div>
</div>
</div>
<!--END NESTED TABS-->
</div>
<div id="tab-3">Tab 3 Content</div>
</div>
</div>
<!--End Tabs-->
<script type="text/javascript">
jQuery(document).ready(function(){
$('#tab-container1 ul').tabs();
});
</script>
JS:
jQuery.fn.tabs = function () {
return this.each(function () {
var ul = jQuery(this);
ul.find('a[href^=#]').each(function (i) {
var tablink = jQuery(this);
if (i) {
jQuery(tablink.attr('href')).hide();
}
else {
tablink.addClass('current');
}
tablink.click(function () {
jQuery(ul.find('a.current').removeClass('current').attr('href')).hide();
jQuery(tablink.addClass('current').attr('href')).show();
if(tablink.attr('rel')){
$("#tab-preloader").show();
$.ajax(
{
url: tablink.attr('rel'),
cache: false,
success: function(message)
{
jQuery(tablink.attr('href')).empty().append(message);
$("#tab-preloader").hide();
}
});
};
return false;
});
});
});
};
I am having a problem with nested tabs. When I click on Tab 2 I need Nested 1 to display by default. Instead it just shows a blank tab until I click Nested 2 and click back to Nested 1.
I'd love to be able to fix this by just adding something to the ready function if possible because changing the actual .js file is a pain... Thanks in advanace!
HTML:
<!--Begin Tabs-->
<div id="tab-container1">
<ul class="tabs">
<li><a href="#tab-1">Tab 1</a></li>
<li><a href="#tab-2">Tab 2</a></li>
<li><a href="#tab-3" rel="external-4.html">Tab 3</a></li>
</ul>
<div class="tab-panel">
<div id="tab-1">Tab 1 Content</div>
<div id="tab-2">
<!--BEGIN NESTED TABS-->
<div class="tab-carousel">
<div id="tab1-N">
<ul id="ul-N" class="tabs-nested">
<li><a href="#tab1-a" rel="external-1.html">Nested 1</a></li>
<li><a href="#tab1-b" rel="external-2.html">Nested 2</a></li>
<li><a href="#tab1-c" rel="external-3.html">Nested 3</a></li>
</ul>
<div class="tab-panel-nested">
<div id="tab1-a">Nested Tab One Content</div>
<div id="tab1-b">Nested Tab Two Content</div>
<div id="tab1-c">Nested Tab Three Content</div>
</div>
</div>
</div>
<!--END NESTED TABS-->
</div>
<div id="tab-3">Tab 3 Content</div>
</div>
</div>
<!--End Tabs-->
<script type="text/javascript">
jQuery(document).ready(function(){
$('#tab-container1 ul').tabs();
});
</script>
JS:
jQuery.fn.tabs = function () {
return this.each(function () {
var ul = jQuery(this);
ul.find('a[href^=#]').each(function (i) {
var tablink = jQuery(this);
if (i) {
jQuery(tablink.attr('href')).hide();
}
else {
tablink.addClass('current');
}
tablink.click(function () {
jQuery(ul.find('a.current').removeClass('current').attr('href')).hide();
jQuery(tablink.addClass('current').attr('href')).show();
if(tablink.attr('rel')){
$("#tab-preloader").show();
$.ajax(
{
url: tablink.attr('rel'),
cache: false,
success: function(message)
{
jQuery(tablink.attr('href')).empty().append(message);
$("#tab-preloader").hide();
}
});
};
return false;
});
});
});
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论