简体   繁体   English

如何使用bootstrap,jquery使选项卡的上一个和下一个按钮?

[英]How to make previous and next button for tabs using bootstrap ,jquery?

Below I have added dynamic tabs with content working code now I want to add previous and next button in this. 下面,我添加了带有内容工作代码的动态标签,现在我想在其中添加上一个和下一个按钮。

If I press next it should move to menu1, menu2, menu3 with tabs content and if I press previous it should move to previous tabs with responding data .how can I make this using jquery? 如果我按下next,它将移动到带有标签内容的menu1,menu2,menu3;如果我按下previous,它将移动到带有响应数据的前一个标签。如何使用jquery做到这一点? anyone help me out to move forward 任何人都可以帮助我前进

 $(document).ready(function(){ $(".nav-tabs a").click(function(){ $(this).tab('show'); }); }); 
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="container"> <h2>Dynamic Tabs</h2> <ul class="nav nav-tabs"> <li class="active"><a href="#home">Home</a></li> <li><a href="#menu1">Menu 1</a></li> <li><a href="#menu2">Menu 2</a></li> <li><a href="#menu3">Menu 3</a></li> </ul> <div class="tab-content"> <div id="home" class="tab-pane fade in active"> <h3>HOME</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> </div> <div id="menu1" class="tab-pane fade"> <h3>Menu 1</h3> <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> </div> <div id="menu2" class="tab-pane fade"> <h3>Menu 2</h3> <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p> </div> <div id="menu3" class="tab-pane fade"> <h3>Menu 3</h3> <p>Eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p> </div> </div> </div> 

Here is an approximation of how you would solve this problem. 这是您将如何解决此问题的近似方法。

  1. You can get the selected tab using a query selector like this .nav-tabs>li.active 您可以使用查询选择器(如.nav-tabs>li.active来获取所选标签。
  2. Once you have the active tab, you can use the nextElementSibling or previousElementSibling property to get the next or previous tab , see MDN docs for details. 拥有活动选项卡后,可以使用nextElementSiblingpreviousElementSibling属性获取下一个或上一个选项卡,有关详细信息,请参见MDN文档
  3. Once you have the next tab, you can call show on it. 进入下一个标签后,您可以在其上调用show。

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

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