您可以看到此参考,但如果此链接已被删除,请阅读此说明:
使用单行 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('切换')
手动切换模式。在模态实际显示或隐藏之前(即在显示.bs.modal 或 hidden.bs.modal 事件发生之前)返回给调用者。
$('#myModal').modal('toggle')
.modal('显示')
手动打开一个模态。在模态实际显示之前(即在 shown.bs.modal 事件发生之前)返回给调用者。
$('#myModal').modal('show')
.modal('隐藏')
手动隐藏模态。在模态实际上被隐藏之前(即在 hidden.bs.modal 事件发生之前)返回给调用者。
$('#myModal').modal('hide')
.modal('handleUpdate')
如果模态在打开时的高度发生变化(即出现滚动条时),手动重新调整模态的位置。
$('#myModal').modal('handleUpdate')
.modal('处置')
销毁元素的模态。
活动
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...
})