最近读bootstarp 的js部分的代码 有个很疑惑的地方,求各路英雄好汉给个解答,万分感谢!<code>!function ($) { "use strict"; // jshint ;_;
/* ALERT CLASS DEFINITION
* ====================== */ var dismiss = '[data-dismiss="alert"]'
, Alert = function (el) {
$(el).on('click', dismiss, this.close)
} Alert.prototype.close = function (e) {
var $this = $(this)
, selector = $this.attr('data-target')
, $parent if (!selector) {
selector = $this.attr('href')
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
} $parent = $(selector) e && e.preventDefault() $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent()) $parent.trigger(e = $.Event('close')) if (e.isDefaultPrevented()) return $parent.removeClass('in') function removeElement() {
$parent
.trigger('closed')
.remove()
} $.support.transition && $parent.hasClass('fade') ?
$parent.on($.support.transition.end, removeElement) :
removeElement()
}
/* ALERT PLUGIN DEFINITION
* ======================= */ var old = $.fn.alert $.fn.alert = function (option) {
return this.each(function () {
var $this = $(this)
, data = $this.data('alert')
if (!data) $this.data('alert', (data = new Alert(this)))
if (typeof option == 'string') data[option].call($this)
})
} $.fn.alert.Constructor = Alert
/* ALERT NO CONFLICT
* ================= */ $.fn.alert.noConflict = function () {
$.fn.alert = old
return this
}
/* ALERT DATA-API
* ============== */ $(document).on('click.alert.data-api', dismiss, Alert.prototype.close)}(window.jQuery);红色地方 一直搞不明白到底这句话的作用是什么 bootstarp,源码,js
/* ALERT CLASS DEFINITION
* ====================== */ var dismiss = '[data-dismiss="alert"]'
, Alert = function (el) {
$(el).on('click', dismiss, this.close)
} Alert.prototype.close = function (e) {
var $this = $(this)
, selector = $this.attr('data-target')
, $parent if (!selector) {
selector = $this.attr('href')
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
} $parent = $(selector) e && e.preventDefault() $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent()) $parent.trigger(e = $.Event('close')) if (e.isDefaultPrevented()) return $parent.removeClass('in') function removeElement() {
$parent
.trigger('closed')
.remove()
} $.support.transition && $parent.hasClass('fade') ?
$parent.on($.support.transition.end, removeElement) :
removeElement()
}
/* ALERT PLUGIN DEFINITION
* ======================= */ var old = $.fn.alert $.fn.alert = function (option) {
return this.each(function () {
var $this = $(this)
, data = $this.data('alert')
if (!data) $this.data('alert', (data = new Alert(this)))
if (typeof option == 'string') data[option].call($this)
})
} $.fn.alert.Constructor = Alert
/* ALERT NO CONFLICT
* ================= */ $.fn.alert.noConflict = function () {
$.fn.alert = old
return this
}
/* ALERT DATA-API
* ============== */ $(document).on('click.alert.data-api', dismiss, Alert.prototype.close)}(window.jQuery);红色地方 一直搞不明白到底这句话的作用是什么 bootstarp,源码,js
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货