All,
I have nested JQuery UI tabs. I want to implement a reloadTab functionality for a nested tab. Currently the following code has static fragments for nested tabs, but eventually they will have urls, so the tabs can behave as ajax tabs. How can I achieve the reloadTab functionality?
<html>
<head>
<link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/ui-lightness/jquery-ui.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$('#tabContainer').tabs({ selected: 0 });
$('#fragment-1').tabs({ selected: 1 });
});
function reloadTab(tabindex)
{
var smalltabs = $('#fragment-1').tabs({cache:false, spinner:'',selected:0});
$('#tabContainer').tabs('load', smalltabs.tabs('option','selected'));
$('#fragment-1').tabs('load', tabindex);
}
</script>
</head>
<body>
<div id="tabContainer">
<ul>
<li><a href="#fragment-1"><span>TAB1</span></a></li>
<li><a href="#fragment-2"><span>TAB2</span></a></li>
<li><a href="#fragment-3"><span>TAB3</span></a></li>
</ul>
<div id="fragment-1">
<ul class="innerNav" >
<li><a href="#fragment-1a"><span>INNERTAB1</span></a></li>
<li><a href="#fragment-1b"><span>INNERTAB开发者_开发百科2</span></a></li>
</ul>
<div id="fragment-1a" class="innerFragment">Content of inner tab 1</div>
<div id="fragment-1b" class="innerFragment">Content of inner tab 2
<br><a href="Javascript:reloadTab(1);">Reload tab content</a></div>
</div>
<div id="fragment-2"></div>
<div id="fragment-3"></div>
</div>
</body>
</html>
Thanks
From the docs:
var $tabs = $('#example').tabs();
var selected = $tabs.tabs('option', 'selected'); // => 0
EDIT
I copied your file, and made the following changes:
Change the reload link to look like this:
href="#" id="reload"
(markdown keeps converting my anchor tag to a link)
- Change the jquery to this:
$(function() { $('#tabContainer').tabs({ selected: 0 }); $('#fragment-1').tabs({ selected: 0 }); $('#reload').click(function(){ var $tabs = $('#fragment-1').tabs(); reloadTab($tabs.tabs('option', 'selected')); }); }); function reloadTab(tabindex) { //alert(tabindex); //un-comment for proof. var smalltabs = $('#fragment-1').tabs({cache:false, spinner:'',selected:0}); $('#tabContainer').tabs('load', smalltabs.tabs('option','selected')); $('#fragment-1').tabs('load', tabindex); }
精彩评论