Just a quick question to see if anyone knows of any jquery tabs plugins that run based on a similar structure to:
<div class="tabs">
<div>
<h4>Tab one</h4>
<p>Lorem Ipsum</p>
</div>
<div>
<h4>Tab two</h4>
<p>Lorem Ipsum</p>
</div>
</div>
Where the plugin grabs the title of the tabs from the h4s? I can only se开发者_如何学JAVAem to find plugins that use the structure:
<div id="tabs">
<ul>
<li><a href="#tabs-1">Nunc tincidunt</a></li>
<li><a href="#tabs-2">Proin dolor</a></li>
<li><a href="#tabs-3">Aenean lacinia</a></li>
</ul>
<div id="tabs-1">
<p>Tab 1 content</p>
</div>
<div id="tabs-2">
<p>Tab 2 content</p>
</div>
<div id="tabs-3">
<p>Tab 3 content</p>
</div>
</div>
I assume the only other way to use these plugins would be to grab the titles, remove them, add them into a list at the top of the html and then run the plugin based on that? I just ask as I am quite new to jQuery so I'm not sure how I would go about it and just wondered if there was a plugin already in existence that anyone knew of.
If not, not to worry, I'll have to get busy with the docs and give it a go!
Cheers
I managed to put something together to get the html to the correct structure to use jQuery UI tabs on - Hopefully someone can learn something from this!
$(document).ready(function() {
$.fn.reverse = [].reverse; //Set the reverse function
$('#tabs div h4').reverse().prependTo('#tabs'); //Grab the headings and reverse them, then prepend to outer div
$('#tabs h4').wrap('<li></li>'); //wrap each heading in an li
$('#tabs > li').wrapAll('<ul class="tabheadings"></ul>'); //wrap all li's in ul
$('#tabs ul li h4').each(function(){
$(this).replaceWith('<a>' + $(this).text() + '</a>'); //for each heading replace with an anchor but keep innards
});
$('#tabs div.in_content_box').each(function(i){
$( this ).attr('id', 'tabs-' + (i+1)); //for each div add an id with an incremental number
});
$('#tabs ul li a').each(function(i){
$( this ).attr('href', '#tabs-' + (i+1)); //match the href on the anchor with the id above
});
});
jQuery Accessible Tabs is almost there, except the header sits outside of the target div.
精彩评论