你可以看到这篇参考文献,但如果这个链接已被删除,请阅读下面的描述:
用id myModal调用一个模态,只需一行JavaScript代码:
$('#myModal').modal(options)
选项
选项可以通过数据属性或JavaScript传递。对于数据属性,将选项名称附加到data-,如data- background =""。
|-----------|-------------|--------|---------------------------------------------|
| 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
})
模式(’toggle’)
手动切换一个模式。在模态实际显示或隐藏之前(即在show .bs.modal或hidden.bs.modal事件发生之前)返回调用者。
$('#myModal').modal('toggle')
.modal(显示)
手动打开一个模式。在模态实际显示之前(即在show .bs.modal事件发生之前)返回给调用者。
$('#myModal').modal('show')
模式(’hide’)
手动隐藏模式。在modal实际被隐藏之前(即在hidden.bs.modal事件发生之前)返回给调用者。
$('#myModal').modal('hide')
模式(’handleUpdate’)
手动调整模式的位置,如果模式的高度变化,而它是打开的(即,情况下滚动条出现)。
$('#myModal').modal('handleUpdate')
模式(’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...
})