gpt4 book ai didi

jquery - Twitter-Bootstrap Modal on Modal 自定义关闭

转载 作者:行者123 更新时间:2023-12-01 03:17:43 28 4
gpt4 key购买 nike

使用 twitter bootstrap 框架进行 Web 应用程序。我正在使用一个模态,其中我调用另一个模态,其中一个模态位于另一个模态之上。目前,如果您单击关闭“x”按钮,它将关闭两个模式窗口。我只想关闭顶部模式。

Modal 类定义从 bootstrap.js 中的第 750 行开始。

模态 HTML

<div class="modal fade hide modal-creator" id="myModal_crop_image" style="display: none;height:600px;" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" data-target="#myModal_crop_image">×</button>
<h3>Create New Gallery</h3>
</div>
<div class="modal-body">
<img style="height:50%;" src="<?php echo base_url(); ?>data/001/images/album/014.jpg" alt="" />
</div><!-- /modal-body -->

<div class="modal-footer">

</div>

BootStrap JS

!function ($) {

"use strict"; // jshint ;_;


/* MODAL CLASS DEFINITION
* ====================== */

var Modal = function (element, options) {
this.options = options
this.$element = $(element)
.delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
}

Modal.prototype = {

constructor: Modal

, toggle: function () {
return this[!this.isShown ? 'show' : 'hide']()
}

, show: function () {
var that = this
, e = $.Event('show')

this.$element.trigger(e)

if (this.isShown || e.isDefaultPrevented()) return

$('body').addClass('modal-open')

this.isShown = true

this.escape()

this.backdrop(function () {
var transition = $.support.transition && that.$element.hasClass('fade')

if (!that.$element.parent().length) {
that.$element.appendTo(document.body) //don't move modals dom position
}

that.$element
.show()

if (transition) {
that.$element[0].offsetWidth // force reflow
}

that.$element
.addClass('in')
.attr('aria-hidden', false)
.focus()

that.enforceFocus()

transition ?
that.$element.one($.support.transition.end, function () { that.$element.trigger('shown') }) :
that.$element.trigger('shown')

})
}

, hide: function (e) {
e && e.preventDefault()

var that = this

e = $.Event('hide')

this.$element.trigger(e)

if (!this.isShown || e.isDefaultPrevented()) return

this.isShown = false

$('body').removeClass('modal-open')

this.escape()

$(document).off('focusin.modal')

this.$element
.removeClass('in')
.attr('aria-hidden', true)

$.support.transition && this.$element.hasClass('fade') ?
this.hideWithTransition() :
this.hideModal()
}

, enforceFocus: function () {
var that = this
$(document).on('focusin.modal', function (e) {
if (that.$element[0] !== e.target && !that.$element.has(e.target).length) {
that.$element.focus()
}
})
}

, escape: function () {
var that = this
if (this.isShown && this.options.keyboard) {
this.$element.on('keyup.dismiss.modal', function ( e ) {
e.which == 27 && that.hide()
})
} else if (!this.isShown) {
this.$element.off('keyup.dismiss.modal')
}
}

, hideWithTransition: function () {
var that = this
, timeout = setTimeout(function () {
that.$element.off($.support.transition.end)
that.hideModal()
}, 500)

this.$element.one($.support.transition.end, function () {
clearTimeout(timeout)
that.hideModal()
})
}

, hideModal: function (that) {
this.$element
.hide()
.trigger('hidden')

this.backdrop()
}

, removeBackdrop: function () {
this.$backdrop.remove()
this.$backdrop = null
}

, backdrop: function (callback) {
var that = this
, animate = this.$element.hasClass('fade') ? 'fade' : ''

if (this.isShown && this.options.backdrop) {
var doAnimate = $.support.transition && animate

this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
.appendTo(document.body)

if (this.options.backdrop != 'static') {
this.$backdrop.click($.proxy(this.hide, this))
}

if (doAnimate) this.$backdrop[0].offsetWidth // force reflow

this.$backdrop.addClass('in')

doAnimate ?
this.$backdrop.one($.support.transition.end, callback) :
callback()

} else if (!this.isShown && this.$backdrop) {
this.$backdrop.removeClass('in')

$.support.transition && this.$element.hasClass('fade')?
this.$backdrop.one($.support.transition.end, $.proxy(this.removeBackdrop, this)) :
this.removeBackdrop()

} else if (callback) {
callback()
}
}
}

这里是js的链接。 http://jsfiddle.net/dazaweb/5cR95/

关于如何解决这个问题有什么想法吗?

最佳答案

在模态定义中的 data-dismiss="modal" 处,添加 data-target="#theIdOfTheModal"

这将告诉它仅关闭该特定模式

我创建了一个 fiddle 来演示这一点,它实际上可以在有或没有数据目标的情况下工作: Fiddle!

关于jquery - Twitter-Bootstrap Modal on Modal 自定义关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13651599/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com