只是一个简单的问题,看看是否有人知道基于类似结构运行的 jquery tabs 插件:

<div class="tabs">
    <div>
        <h4>Tab one</h4>
        <p>Lorem Ipsum</p>
    </div>

    <div>
        <h4>Tab two</h4>
        <p>Lorem Ipsum</p>
    </div>
</div>

插件在哪里从 h4s 中获取选项卡的标题?我似乎只能找到使用该结构的插件:

<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>

我认为使用这些插件的唯一其他方法是获取标题,删除它们,将它们添加到 html 顶部的列表中,然后基于此运行插件?我只是问,因为我对 jQuery 很陌生,所以我不确定我会如何去做,只是想知道是否已经存在一个任何人都知道的插件。

如果没有,不用担心,我将不得不忙于文档并尝试一下!

干杯

有帮助吗?

解决方案

我设法把东西一起拿到HTML正确的结构使用jQuery UI选项卡上 - !希望有人可以借鉴这样的东西

$(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 可访问选项卡 几乎就在那里,除了标题位于目标 div 之外。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top