As mentioned above, Bootstrap has a Data API where you can write data attributes into
the HTML of the page. If you need to turn off the Data API, you can unbind the attributes
by adding the following line of JavaScript:
$('body').off('.data-api')
If you need to disable a single plugin, you can do it programmatically using
the namespace of the plugin along with the data-api namespace:
$('body').off('.alert.data-api')
Modal
A modal is a child window that is layered over its parent window.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<divclass="modal hide fade"><divclass="modal-header"><buttontype="button"class="close"data-dismiss="modal"aria-hidden="true">
×</button><h3>Modal header</h3></div><divclass="modal-body"><p>One fine body...</p></div><divclass="modal-footer"><ahref="#"class="btn">Close</a><ahref="#"class="btn btn-primary">Save changes</a></div></div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!-- Button to trigger modal --><ahref="#myModal"role="button"class="btn"data-toggle="modal">Launch demo modal</a><!-- Modal --><divid="myModal"class="modal hide fade"tabindex="-1"role="dialog"aria-labelledby="myModalLabel"aria-hidden="true"><divclass="modal-header"><buttontype="button"class="close"data-dismiss="modal"aria-hidden="true">×</button><h3id="myModalLabel">Modal header</h3></div><divclass="modal-body"><p>One fine body...</p></div><divclass="modal-footer"><buttonclass="btn"data-dismiss="modal"aria-hidden="true">Close</button><buttonclass="btn btn-primary">Save changes</button></div></div>
To start with, set data-toggle="modal" on the link or button
that you want to use to invoke the modal and then set the data-target="#foo" to the
ID of the modal that you’d like to use.
To call a modal with id="myModal", use a single line of JavaScript:
$('#myModal').modal(options)
To use the data attributes, prepend data- to the option name (e.g., data-backdrop="")
Name
Type
Default
Description
backdrop
Boolean
true
Set to false if you don’t want the modal to be closed when the user clicks outside of the modal.
keyboard
Boolean
true
Closes the modal when escape key is pressed; set to false to disable.
show
Boolean
true
Shows the modal when initialized.
remote
path
false
Using the jQuery .load method, inject content into the modal body. If an href with a valid URL is added, it will load that content.
The .button method can be applied to any class or ID. To enable all buttons in
the .nav-tabs via JavaScript, add the following code:
$('.nav-tabs').button()