小弟学习js 看源码中 希望大侠帮帮忙
越详细越好 谢谢!
html代码:
<ul class="nav nav-tabs" id="tsp">
<li class="active"><a data-toggle="tab" href="#home">首页</a></li>
<li><a data-toggle="tab" href="#profile">介绍</a></li>
</ul>
<div class="tab-content" id="mytspContent">
<div id="home" class="tab-pane fade in active">
<p>1 </p>
</div>
<div id="profile" class="tab-pane fade">
<p>2</p>
</div>
</div>
-----------------
js:代码(
<script src="javascript_files/jquery.js"></script><script src="javascript_files/bootstrap-tab.js"></script>)
下面的是bootstrap-tab.js的js
!function($) {
"use strict"
var Tab = function(element) {
this.element = $(element)
}
Tab.prototype = {
constructor: Tab,
show: function() {
var $this = this.element,
$ul = $this.closest('ul:not(.dropdown-menu)'),
selector = $this.attr('data-target'),
previous,
$target
if (!selector) {
selector = $this.attr('href')
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '')
}
if ($this.parent('li').hasClass('active')) return
previous = $ul.find('.active a').last()[0]
$this.trigger({
type: 'show',
relatedTarget: previous
})
$target = $(selector)
this.activate($this.parent('li'), $ul)
this.activate($target, $target.parent(),
function() {
$this.trigger({
type: 'shown',
relatedTarget: previous
})
})
},
activate: function(element, container, callback) {
var $active = container.find('> .active'),
transition = callback && $.support.transition && $active.hasClass('fade')
function next() {
$active.removeClass('active').find('> .dropdown-menu > .active').removeClass('active')
element.addClass('active')
if (transition) {
element[0].offsetWidth
element.addClass('in')
} else {
element.removeClass('fade')
}
if (element.parent('.dropdown-menu')) {
element.closest('li.dropdown').addClass('active')
}
callback && callback()
}
transition ? $active.one($.support.transition.end, next) : next()
$active.removeClass('in')
}
}
$.fn.tab = function(option) {
return this.each(function() {
var $this = $(this),
data = $this.data('tab')
if (!data) $this.data('tab', (data = new Tab(this)))
if (typeof option == 'string') data[option]()
})
}
$.fn.tab.Constructor = Tab
$(function() {
$('body').on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]',
function(e) {
e.preventDefault()
$(this).tab('show')
})
})
} (window.jQuery);再一次感谢大侠!
添加回答
举报
0/150
提交
取消