你可以查看这个参考链接,如果此链接已经被移除,请阅读以下说明:
使用单行JavaScript代码调用ID为myModal的模态框:
$('#myModal').modal(options)
选项
可以通过数据属性或JavaScript传递选项。对于数据属性,将选项名称附加到data-,例如data-backdrop=""。
|-----------|-------------|--------|---------------------------------------------|
| Name | Type | Default| Description |
|-----------|-------------|--------|---------------------------------------------|
| backdrop | boolean or | true | Includes a modal-backdrop element. |
| | the string | | Alternatively, specify static for a |
| | 'static' | | backdrop which doesn't close the modal |
| | | | on click. |
| | | | |
| keyboard | boolean | true | Closes the modal when escape key is pressed.|
| | | | |
| focus | boolean | true | Puts the focus on the modal when initialized|
| | | | |
| show | boolean | true | Shows the modal when initialized. |
|-----------|-------------|--------|---------------------------------------------|
方法
异步方法和转换
所有API方法都是异步的,并启动了一个转换。它们在转换开始时立即返回给调用者,但在转换结束之前。此外,在正在转换的组件上调用的方法将被忽略。
请参阅我们的JavaScript文档以获取更多信息。
.modal(选项)
将您的内容激活为模态。接受可选的选项对象。
$('#myModal').modal({
keyboard: false
})
.modal('toggle')
手动切换模态框的显示和隐藏状态。在模态框实际被显示或隐藏之前返回给调用者(即在shown.bs.modal或hidden.bs.modal事件发生之前)。
$('#myModal').modal('toggle')
.modal('show')
手动打开一个模态框。在实际显示模态框之前(即在shown.bs.modal事件发生之前),会立即返回调用者。
$('#myModal').modal('show')
.modal('hide')
手动隐藏模态框。在模态框实际被隐藏之前(即在hidden.bs.modal事件发生之前),返回给调用者。
$('#myModal').modal('hide')
.modal('handleUpdate')
如果模态框在打开时高度发生变化(即出现滚动条),则手动调整模态框的位置。
这个方法可以帮助你在使用模态框时,当模态框的高度发生变化时,手动调整模态框的位置,以确保它始终处于正确的位置。
$('#myModal').modal('handleUpdate')
.modal('dispose')
销毁一个元素的模态框。
事件
Bootstrap的模态框类提供了一些事件来钩取模态框功能。所有模态框事件都在模态框本身触发(即在**处触发)。
类型 描述
|----------------|--------------------------------------------------------------|
| Event Type | Description |
|----------------|--------------------------------------------------------------|
| show.bs.modal | This event fires immediately when the **show** instance |
| | method is called. If caused by a click, the clicked element |
| | is available as the **relatedTarget** property of the event. |
| | |
| shown.bs.modal | This event is fired when the modal has been made visible to |
| | the user (will wait for CSS transitions to complete). If |
| | caused by a click, the clicked element is available as the |
| | **relatedTarget** property of the event. |
| | |
| hide.bs.modal | This event is fired immediately when the **hide** instance |
| | method has been called. |
| | |
| hidden.bs.modal| This event is fired when the modal has finished being hidden |
| | from the user (will wait for CSS transitions to complete). |
|----------------|--------------------------------------------------------------|
$('#myModal').on('hidden.bs.modal', function (e) {
// do something...
})
$("#yourModal").modal()
还是$('.modal').modal()
来初始化你的模态框? - merv