mirror of https://github.com/twbs/bootstrap.git
remove jquery in tab docs
This commit is contained in:
parent
eecd75db00
commit
cd21ca074e
|
@ -524,19 +524,25 @@ You can activate a tab or pill navigation without writing any JavaScript by simp
|
||||||
Enable tabbable tabs via JavaScript (each tab needs to be activated individually):
|
Enable tabbable tabs via JavaScript (each tab needs to be activated individually):
|
||||||
|
|
||||||
{{< highlight js >}}
|
{{< highlight js >}}
|
||||||
$('#myTab a').on('click', function (e) {
|
var triggerTabList = [].slice.call(document.querySelectorAll('#myTab a'))
|
||||||
|
triggerTabList.forEach(function (triggerEl) {
|
||||||
|
var tabTrigger = new bootstrap.Tab(triggerEl)
|
||||||
|
|
||||||
|
triggerEl.addEventListener('click', function (e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
$(this).tab('show')
|
tabTrigger.show()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
{{< /highlight >}}
|
{{< /highlight >}}
|
||||||
|
|
||||||
You can activate individual tabs in several ways:
|
You can activate individual tabs in several ways:
|
||||||
|
|
||||||
{{< highlight js >}}
|
{{< highlight js >}}
|
||||||
$('#myTab a[href="#profile"]').tab('show') // Select tab by name
|
var triggerEl = document.querySelector('#myTab a[href="#profile"]')
|
||||||
$('#myTab li:first-child a').tab('show') // Select first tab
|
bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name
|
||||||
$('#myTab li:last-child a').tab('show') // Select last tab
|
|
||||||
$('#myTab li:nth-child(3) a').tab('show') // Select third tab
|
var triggerFirstTabEl = document.querySelector('#myTab li:first-child a')
|
||||||
|
bootstrap.Tab.getInstance(triggerFirstTabEl).show() // Select first tab
|
||||||
{{< /highlight >}}
|
{{< /highlight >}}
|
||||||
|
|
||||||
### Fade effect
|
### Fade effect
|
||||||
|
@ -558,7 +564,7 @@ To make tabs fade in, add `.fade` to each `.tab-pane`. The first tab pane must a
|
||||||
{{< partial "callout-danger-async-methods.md" >}}
|
{{< partial "callout-danger-async-methods.md" >}}
|
||||||
{{< /callout >}}
|
{{< /callout >}}
|
||||||
|
|
||||||
#### $().tab
|
#### constructor
|
||||||
|
|
||||||
Activates a tab element and content container. Tab should have either a `data-target` or an `href` targeting a container node in the DOM.
|
Activates a tab element and content container. Tab should have either a `data-target` or an `href` targeting a container node in the DOM.
|
||||||
|
|
||||||
|
@ -586,24 +592,37 @@ Activates a tab element and content container. Tab should have either a `data-ta
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(function () {
|
var firstTabEl = document.querySelector('#myTab li:last-child a')
|
||||||
$('#myTab li:last-child a').tab('show')
|
var firstTab = new bootstrap.Tab(firstTabEl)
|
||||||
})
|
|
||||||
|
firstTab.show()
|
||||||
</script>
|
</script>
|
||||||
{{< /highlight >}}
|
{{< /highlight >}}
|
||||||
|
|
||||||
#### .tab('show')
|
#### show
|
||||||
|
|
||||||
Selects the given tab and shows its associated pane. Any other tab that was previously selected becomes unselected and its associated pane is hidden. **Returns to the caller before the tab pane has actually been shown** (i.e. before the `shown.bs.tab` event occurs).
|
Selects the given tab and shows its associated pane. Any other tab that was previously selected becomes unselected and its associated pane is hidden. **Returns to the caller before the tab pane has actually been shown** (i.e. before the `shown.bs.tab` event occurs).
|
||||||
|
|
||||||
{{< highlight js >}}
|
{{< highlight js >}}
|
||||||
$('#someTab').tab('show')
|
var someTabTriggerEl = document.querySelector('#someTabTrigger')
|
||||||
|
var tab = new bootstrap.Tab(someTabTriggerEl)
|
||||||
|
|
||||||
|
tab.show()
|
||||||
{{< /highlight >}}
|
{{< /highlight >}}
|
||||||
|
|
||||||
#### .tab('dispose')
|
#### dispose
|
||||||
|
|
||||||
Destroys an element's tab.
|
Destroys an element's tab.
|
||||||
|
|
||||||
|
#### getInstance
|
||||||
|
|
||||||
|
*Static* method which allows you to get the tab instance associated with a DOM element
|
||||||
|
|
||||||
|
{{< highlight js >}}
|
||||||
|
var triggerEl = document.querySelector('#trigger')
|
||||||
|
var tab = bootstrap.Tab.getInstance(triggerEl) // Returns a Bootstrap tab instance
|
||||||
|
{{< /highlight >}}
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
When showing a new tab, the events fire in the following order:
|
When showing a new tab, the events fire in the following order:
|
||||||
|
@ -643,7 +662,8 @@ If no tab was already active, then the `hide.bs.tab` and `hidden.bs.tab` events
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{{< highlight js >}}
|
{{< highlight js >}}
|
||||||
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
var tabEl = document.querySelector('a[data-toggle="tab"]')
|
||||||
|
tabEl.addEventListener('shown.bs.tab', function (e) {
|
||||||
e.target // newly activated tab
|
e.target // newly activated tab
|
||||||
e.relatedTarget // previous active tab
|
e.relatedTarget // previous active tab
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue