Latest web development tutorials

Bootstrap tabs (Tab) widget

Tab (Tab) in Bootstrap navigation elements introduced in the chapter. By combining a number of data attributes, you can easily create a tab interface. With this plugin, you can put content in tabs or capsule tabs and even drop down menu tab.

If you want to refer to the individual plug-in features, you need to referencetab.js.Or, as Bootstrap plugin Overview chapter mentioned, you can refer tobootstrap.jsor compressed version ofbootstrap.min.js.

usage

You can enable tabs in two ways:

  • Through data attributes: You need to add data-toggle = "tab"ordata-toggle = "pill"to anchor text links.

    Nav nav-tabsand add class to theul,and will be applied Bootstrap label style , and addnavnav-pills toulclass, and will be applied Bootstrap capsule style .

    <Ul class = "nav nav-tabs">
    	<Li> <a href="#identifier" data-toggle="tab"> Home </a> </ li>
    	...
    </ Ul>
    
  • By JavaScript: You can use the tabs to enable Javscript, as follows:
    $ ( '# MyTab a'). Click (function (e) {
      e.preventDefault ()
      $ (This) .tab ( 'show')
    })
    

    The following example demonstrates different ways to activate the various tabs:

    // Select the name of the tab by $ ( '# myTab a [href = "# profile"]'). Tab ( 'show')
    
    // Select the first tab $ ( '# myTab a: first') tab ( 'show').
    
    // Select the last tab $. ( '# MyTab a: last') tab ( 'show')
    
    // Select the third tab (zero-indexed)
    $ ( '# MyTab li: eq (2) a') tab ( 'show').
    

Fade effect

If you need to set tabs fade effect, add.fade behind each .tab-pane.The first tab must be added.in class to fade in the original content, as shown in the following examples:

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

Examples

The following example demonstrates the use of property data tabs (Tab) and plug-fade effects:

Examples

<Ul id = "myTab" class = "nav nav-tabs" > <Li class = "active"> <A href = "#home" data-toggle = "tab"> W3Cschool Home </ a> </ Li> <Li> <a href = "#ios" data-toggle = "tab"> iOS </ a> </ li> <Li class = "dropdown"> <A href = "#" id = "myTabDrop1" class = "dropdown-toggle" data-toggle = "dropdown"> Java <b class = "caret"> </ b> </ A> <Ul class = "dropdown-menu" role = "menu" aria-labelledby = "myTabDrop1"> <Li> <a href = "#jmeter" tabindex = "-1" data-toggle = "tab"> jmeter </ a> </ li> <Li> <a href = "#ejb" tabindex = "-1" data-toggle = "tab"> ejb </ a> </ li> </ Ul> </ Li> </ Ul> <Div id = "myTabContent" class = "tab-content"> <Div class = "tab-pane fade in active" id = "home"> <P> W3Cschoool This tutorial is to provide the latest web site technology, this site provides a free station technical documentation, help the majority of web technology enthusiasts quick start and build their own websites. The first flight early into the line - to learn not only technology, but also a dream. </ P> </ Div> <Div class = "tab-pane fade" id = "ios"> <P> iOS is a developed and published by Apple's mobile operating system. Originally released for the first time iPhone, iPod Touch and Apple TV in 2007. iOS is derived from OS X, they share the Darwin foundation. OS X operating system is used on a Mac, iOS is Apple's mobile version. </ P> </ Div> <Div class = "tab-pane fade" id = "jmeter"> <P> jMeter is an open source test software. It is 100% pure Java application, for load and performance testing. </ P> </ Div> <Div class = "tab-pane fade" id = "ejb"> <P> Enterprise Java Beans (EJB ) is a development framework to create a highly scalable and robust enterprise applications, deployed on a compatible application servers (such as JBOSS, Web Logic, etc.) of J2EE. </ P> </ Div> </ Div>

try it"

The results are as follows:

Tab (Tab) widget

method

. $ () tab:. The method may Activate tab element and the container contents.Tabs need to use adata-target or a point in the container href DOMnode.

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

Examples

The following example demonstrates the tab (Tab) plug-in methods.tab usage.In the present example, the second tab is activeiOS:

Examples

<Ul id = "myTab" class = "nav nav-tabs" > <Li class = "active"> <a href = "#home" data-toggle = "tab"> W3Cschool Home </ a> </ Li> <Li> <a href = "#ios" data-toggle = "tab"> iOS </ a> </ li> <Li class = "dropdown"> <A href = "#" id = "myTabDrop1" class = "dropdown-toggle" data-toggle = "dropdown"> Java <b class = "caret"> </ b> </ A> <Ul class = "dropdown-menu" role = "menu" aria-labelledby = "myTabDrop1"> <Li> <a href = "#jmeter" tabindex = "-1" data-toggle = "tab"> jmeter </ a> </ Li> <Li> <a href = "#ejb" tabindex = "-1" data-toggle = "tab"> ejb </ a> </ Li> </ Ul> </ Li> </ Ul> <Div id = "myTabContent" class = "tab-content"> <Div class = "tab-pane fade in active" id = "home"> <P> W3Cschoool This tutorial is to provide the latest web site technology, this site provides a free station technical documentation, help the majority of web technology enthusiasts quick start and build their own websites. The first flight early into the line - to learn not only technology, but also a dream. </ P> </ Div> <Div class = "tab-pane fade" id = "ios"> <P> iOS is a developed and published by Apple's mobile operating system. Originally released for the first time iPhone, iPod Touch and Apple TV in 2007. iOS is derived from OS X, they share the Darwin foundation. OS X operating system is used on a Mac, iOS is Apple's mobile version. </ P> </ Div> <Div class = "tab-pane fade" id = "jmeter"> <P> jMeter is an open source test software. It is 100% pure Java application, for load and performance testing. </ P> </ Div> <Div class = "tab-pane fade" id = "ejb"> <P> Enterprise Java Beans (EJB ) is a development framework to create a highly scalable and robust enterprise applications, deployed on a compatible application servers (such as JBOSS, Web Logic, etc.) of J2EE. </ P> </ Div> </ Div> <Script> $ (function () {$ ( '# myTab li: eq (1) a') tab ( 'show');.}); </ Script>

try it"

The results are as follows:

Tab (Tab) plug-in method

event

The following table lists the tabs (Tab) plug-in to be used in the event. These events can be used when the hook function.

事件描述实例
show.bs.tab该事件在标签页显示时触发,但是必须在新标签页被显示之前。分别使用event.targetevent.relatedTarget来定位到激活的标签页和前一个激活的标签页。
$('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
  e.target // 激活的标签页
  e.relatedTarget // 前一个激活的标签页
})
shown.bs.tab该事件在标签页显示时触发,但是必须在某个标签页已经显示之后。分别使用event.targetevent.relatedTarget来定位到激活的标签页和前一个激活的标签页。
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  e.target // 激活的标签页
  e.relatedTarget // 前一个激活的标签页
})

Examples

The following example demonstrates the use of tabs (Tab) plug-in event. In the present example, it will display the current and the previous visited tabs:

Examples

<Hr> <P class = "active-tab"> <strong> Activate tab </ strong>: <span> </ span> </ p> <P class = "previous-tab"> <strong> Activate previous tab </ strong>: <span> </ span> </ p> <Hr> <Ul id = "myTab" class = "nav nav-tabs" > <Li class = "active"> <a href = "#home" data-toggle = "tab"> W3Cschool Home </ a> </ li> <Li> <a href = "#ios" data-toggle = "tab"> iOS </ a> </ li> <Li class = "dropdown"> <A href = "#" id = "myTabDrop1" class = "dropdown-toggle" data-toggle = "dropdown"> Java <b class = "caret"> </ b> </ a> <Ul class = "dropdown-menu" role = "menu" aria-labelledby = "myTabDrop1"> <Li> <a href = "#jmeter" tabindex = "-1" data-toggle = "tab"> jmeter </ a> </ li> <Li> <a href = "#ejb" tabindex = "-1" data-toggle = "tab"> ejb </ a> </ li> </ Ul> </ Li> </ Ul> <Div id = "myTabContent" class = "tab-content"> <Div class = "tab-pane fade in active" id = "home"> <P> W3Cschoool This tutorial is to provide the latest web site technology, this site provides a free station technical documentation, help the majority of web technology enthusiasts quick start and build their own websites. The first flight early into the line - to learn not only technology, but also a dream. </ P> </ Div> <Div class = "tab-pane fade" id = "ios"> <P> iOS is a developed and published by Apple's mobile operating system. Originally released for the first time iPhone, iPod Touch and Apple TV in 2007. iOS is derived from OS X, they share the Darwin foundation. OS X operating system is used on a Mac, iOS is Apple's mobile version. </ P> </ Div> <Div class = "tab-pane fade" id = "jmeter"> <P> jMeter is an open source test software. It is 100% pure Java application, for load and performance testing. </ P> </ Div> <Div class = "tab-pane fade" id = "ejb"> <P> Enterprise Java Beans (EJB ) is a development framework to create a highly scalable and robust enterprise applications, deployed on a compatible application servers (such as JBOSS, Web Logic, etc.) of J2EE. </ P> </ Div> </ Div> <Script> $ (function () {$ ( 'a [data-toggle = "tab"]'). On ( 'shown.bs.tab', function (e) {// get activated Tab Name var activeTab = $ (e.target) .text (); // Get a pre-activated name var tab previousTab = $ (e.relatedTarget) .text ( ); $ ( "active-tab span."). html (activeTab); $ ( " previous-tab span.") html (previousTab);.});}); </ script>

try it"

The results are as follows:

Tab (Tab) Plug-in Event