您可以看到此参考,但如果此链接已删除,请阅读以下说明:
用一行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(选项)
将您的内容激活为模式。接受一个可选的options对象。
$('#myModal').modal({
keyboard: false
})
.modal('toggle')
手动切换模态。在模态实际显示或隐藏之前(即在show.bs.modal或hidden.bs.modal事件发生之前)返回到调用者。
$('#myModal').modal('toggle')
.modal('show')
手动打开模式。在实际显示模式之前(即在show.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()
吗?