


Bootstrap must-learn tab page (Tab) plug-in every day_javascript skills
Tab You can easily create a tab interface by combining some data attributes.
"If you want to reference the plugin's functionality alone, then you need to reference tab.js. Alternatively, as mentioned in the Bootstrap Plugin Overview chapter, you can reference bootstrap.js or zip version of bootstrap.min.js "
1. Usage
You can enable tabs in two ways:
Via data attribute: You need to add data-toggle="tab" or data-toggle="pill" to the anchor text link.
Add the nav and nav-tabs classes to ul and the Bootstrap tag style will be applied. Add the nav and nav-pills classes to ul and the Bootstrap capsule style will be applied.
<ul class="nav nav-tabs"> <li><a href="#identifier" data-toggle="tab">Home</a></li> ... </ul>
Via JavaScript: You can use Javscript to enable tabs as follows:
$('#myTab a').click(function (e) { e.preventDefault() $(this).tab('show') })
The following examples demonstrate different ways to activate individual tabs:
// 通过名称选取标签页 $('#myTab a[href="#profile"]').tab('show') // 选取第一个标签页 $('#myTab a:first').tab('show') // 选取最后一个标签页 $('#myTab a:last').tab('show') // 选取第三个标签页(从 0 开始索引) $('#myTab li:eq(2) a').tab('show')
2. Fade in and fade out effect
If you need to set the fade effect for the tab page, please add .fade after each .tab-pane. The first tab must add the .in class in order to fade in and display the initial content, as shown in the example below:
<div class="tab-content"> <div class="tab-pane fade in active" id="home">...</div> <div class="tab-pane fade" id="svn">...</div> <div class="tab-pane fade" id="ios">...</div> <div class="tab-pane fade" id="java">...</div> </div>
3. Method
.$().tab: This method activates tab elements and content containers. The tab needs to use a data-target or an href pointing to the container node in the DOM.
<ul class="nav nav-tabs" id="myTab"> <li class="active"><a href="#identifier" data-toggle="tab">Home</a></li> ..... </ul> <div class="tab-content"> <div class="tab-pane active" id="home">...</div> ..... </div> <script> $(function () { $('#myTab a:last').tab('show') }) </script>
4. Events
The following table lists the events used in the Tab plug-in. These events can be used as hooks in functions.
5. Basic Examples
1. Tag page
The tab page is also commonly known as the tab function.
//基本用法 <ul class="nav nav-tabs"> <li class="active"> <a href="#html5" data-toggle="tab">HTML5</a> </li> <li> <a href="#bootstrap" data-toggle="tab">Bootstrap</a> </li> <li> <a href="#jquery" data-toggle="tab">jQuery</a> </li> <li> <a href="#extjs" data-toggle="tab">ExtJS</a> </li> </ul> <div class="tab-content" style="padding: 10px;"> <div class="tab-pane active" id="html5"> ... </div> <div class="tab-pane" id="bootstrap"> ... </div> <div class="tab-pane" id="jquery"> ... </div> <div class="tab-pane" id="extjs"> ... </div> </div>
//可以设置淡入淡出效果 fade,而 in 表示首选的内容默认显示 <div class="tab-pane fade in active" id="html5"> //也可以换成胶囊式 <ul class="nav nav-pills"> //data-target
Using data-target to bind or not has the same effect
//使用 JavaScript,直接使用 tab 方法。 $('#nav a').on('click', function(e) { e.preventDefault(); $(this).tab('show'); });
//事件,其他雷同 $('#nav a').on('show.bs.tab', function() { alert('调用 tab 时触发!'); }); $('#nav a').on('shown.bs.tab', function() { alert('显示完 tab 时触发!'); });
For more content, please pay attention to the Bootstrap topic: Bootstrap learning tutorial
The above is the entire content of this article, I hope it will be helpful to everyone’s study.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

How to use Bootstrap to get the value of the search bar: Determines the ID or name of the search bar. Use JavaScript to get DOM elements. Gets the value of the element. Perform the required actions.

Use Bootstrap to implement vertical centering: flexbox method: Use the d-flex, justify-content-center, and align-items-center classes to place elements in the flexbox container. align-items-center class method: For browsers that do not support flexbox, use the align-items-center class, provided that the parent element has a defined height.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
