简体   繁体   English

Bootstrap分页和选项卡式元素

[英]Bootstrap Pagination and tabbed elements

I have some content inside of a tabbed element using Bootstrap like so: 我在使用Bootstrap的选项卡元素中有一些内容,如下所示:

<div class="tab-content"> 
   <div class="tab-pane active" id="website-information">
      ...
   </div> 
   <div class="tab-pane" id="personal-information"> 
      ...
   </div> 
   <div class="tab-pane" id="payment-information"> 
      ...
   </div> 
</div> 

And then after this I have some pagination elements like so: 然后在这之后我有一些像这样的分页元素:

<ul class="pager">
   <li class="previous"><a href="#website-information" data-toggle="tab">Previous</a></li>
   <li class="next"><a href="#owner-information" data-toggle="tab">Next</a></li>
</ul>

As you can see the pagination buttons are supposed to take you back a tab and forward a tab respectively whereas right now they are simply pointing to a certain tab that works fine if you only have two tabs but i'm going to possibly have about 4 by the time I am done. 正如你所看到的那样,分页按钮可以让你回到标签并分别转发标签,而现在它们只是指向一个工作正常的标签,如果你只有两个标签,但我可能会有大约4个当我完成时。 I am sure there is an obvious and simple way to make the previous and next buttons actually work with the tabs, I just can't figure it out. 我确信有一种明显而简单的方法可以使前一个和下一个按钮实际上与标签一起使用,我只是想不出来。 Any help and/or suggestions would be appreciated. 任何帮助和/或建议将不胜感激。

This is what bootstrap offers as selecting previously active and the next tab for tab elements. 这是bootstrap提供的选择以前活动和tab元素的下一个选项卡。 But I have no clue how to make them work: 但我不知道如何使它们工作:

$('a[data-toggle="tab"]').on('shown', function (e) {
  e.target // activated tab
  e.relatedTarget // previous tab
})

You will need Javascript to do this. 您将需要Javascript来执行此操作。 HTML doesn't have the functionality to automagically detect the next or previous tab. HTML没有自动检测下一个或上一个选项卡的功能。

Take a look at jQuery, which is required for some of Bootstraps functionality. 看一下jQuery,这是一些Bootstraps功能所必需的。 You are of course not required to use jQuery for this particular problem or effect, depending on your skill level and requirements you could use regular Javascript like any modern browser supports or you could go more advanced and use a little smarter Javascript framework to do some of the work for you. 您当然不需要使用jQuery来解决这个特定问题或影响,具体取决于您的技能水平和要求,您可以像任何现代浏览器支持一样使用常规Javascript,或者您可以更高级并使用更智能的Javascript框架来执行某些操作为你工作。

For example, take a look at the jQuery selectors and the jQuery .children() function 例如,看一下jQuery选择器jQuery .children()函数

Edit 编辑

The default Bootstrap solution you provided there isn't aimed at making the next and previous buttons work. 您在此处提供的默认Bootstrap解决方案并非旨在使下一个和上一个按钮工作。 What it does is pass the "e" that you've clicked of all links that contain data-toggle="tab" , and activate it. 它的作用是传递你点击包含data-toggle="tab"的所有链接的“e data-toggle="tab" ,然后激活它。

You will need to rewrite and modify that piece of code. 您需要重写和修改该段代码。 The selector is part of a possible solution where you select all tabs you have and then have jQuery figure out in which order they are in. You can then have the Next button call "next()" and the Back button "back()" which will then swap the active tab to -1 or +1 basically. 选择器是一个可能的解决方案的一部分,您可以选择所有选项卡,然后让jQuery确定它们所处的顺序。然后您可以使用Next按钮调用“next()”和Back按钮“back()”然后基本上将活动标签交换为-1或+1。

I found a neat example here of how to add Pagination with bootstrap tabs: http://www.bootply.com/60206 我在这里找到了一个简洁的例子,说明如何使用引导标签添加分页: http//www.bootply.com/60206

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM