您的位置:首页 > Web前端 > BootStrap

模态对话框 bootstrap-modal.js

2014-07-14 15:25 375 查看

调用方式

通过data属性

无需编写JavaScript代码即可生成一个对话框。在一个主控元素,例如按钮,上设置
data-toggle="modal"
,然后再设置
data-target="#foo"
href="#foo"
用以指向某个将要被启动的对话框。

<button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>

通过JavaScript

仅用一行JavaScript代码即可启动id为
myModal
的对话框:

$('#myModal').modal(options)

选项

上面的选项都可以通过data属性或JavaScript代码传递给组件。对于data属性,将选项名称附着于
data-
字符串之后,就像
data-backdrop=""
一样。

名称类型默认值描述
backdropbooleantrueIncludes a modal-backdrop element. Alternatively, specify
static
for a backdrop which doesn't close the modal on click.
keyboardbooleantrueCloses the modal when escape key is pressed
showbooleantrueShows the modal when initialized.
remotepathfalseIf a remote url is provided, content will be loaded via jQuery's
load
method and injected into the
.modal-body
. If you're using the data api, you may alternatively use the
href
tag to specify the remote source. An example of this is shown below:

<a data-toggle="modal" href="remote.html" data-target="#modal">click me</a>


方法

.modal(options)

让你指定的内容变成一个模态对话框。接受一个可选的参数
object
.

$('#myModal').modal({

keyboard: false

})

.modal('toggle')

手动打开或隐藏一个模态对话框。

$('#myModal').modal('toggle')

.modal('show')

手动打开一个模态对话框。

$('#myModal').modal('show')

.modal('hide')

手动隐藏一个模态对话框。

$('#myModal').modal('hide')

事件

Bootstrap中的模态对话框对外暴露了一些事件允许你监听。

事件描述
showThis event fires immediately when the
show
instance method is called.
shownThis event is fired when the modal has been made visible to the user (will wait for css transitions to complete).
hideThis event is fired immediately when the
hide
instance method has been called.
hiddenThis event is fired when the modal has finished being hidden from the user (will wait for css transitions to complete).
$('#myModal').on('hidden', function () {

// do something…

})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: