Phương thức JS Bootstrap
Phương thức JS (modal.js)
Plugin Modal là một hộp thoại/cửa sổ bật lên được hiển thị ở đầu trang hiện tại.
Để biết hướng dẫn về Modal, hãy đọc Hướng dẫn về Modal Bootstrap của chúng tôi.
Các lớp Plugin Modal
Class | Description |
---|---|
.modal | Creates a modal |
.modal-content | Styles the modal properly with border, background-color, etc. Use this class to add the modal's header, body, and footer. |
.modal-header | Defines the style for the header of the modal |
.modal-body | Defines the style for the body of the modal |
.modal-footer | Defines the style for the footer in the modal. Note: This area is right-aligned by default. To change this, overwrite CSS with text-align:left|center |
.modal-sm | Specifies a small modal |
.modal-lg | Specifies a large modal |
.fade | Adds an animation/transition effect which fades the modal in and out |
Kích hoạt thuộc tính Modal Via data-*
Thêm data-toggle="modal"
và data-target="#modalID"
vào bất kỳ phần tử nào.
Lưu ý: Đối với các phần tử <a>
, hãy bỏ qua data-target
và thay vào đó hãy sử dụng href="#modalID"
:
Ví dụ
<!-- Buttons -->
<button type="button" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Links -->
<a data-toggle="modal" href="#myModal">Open Modal</a>
<!-- Other elements -->
<p data-toggle="modal" data-target="#myModal">Open Modal</p>
Hãy tự mình thử » Kích hoạt qua JavaScript
Kích hoạt thủ công với:
Tùy chọn phương thức
Các tùy chọn có thể được chuyển qua thuộc tính dữ liệu hoặc JavaScript. Đối với thuộc tính dữ liệu, hãy thêm tên tùy chọn vào data-, như trong data-backdrop="".
Name | Type | Default | Description | Try it |
---|---|---|---|---|
backdrop | boolean or the string "static" | true |
Specifies whether the modal should have a dark overlay:
If you specify the value "static", it is not possible to close the modal when clicking outside of it |
Using JS Using data |
keyboard | boolean | true | Specifies whether the modal can be closed with the escape key (Esc):
|
Using JS Using data |
show | boolean | true | Specifies whether to show the modal when initialized | Using JS Using data |
Phương thức phương thức
Bảng sau liệt kê tất cả các phương thức phương thức có sẵn.
Method | Description | Try it |
---|---|---|
.modal( options ) | Activates the content as a modal. See options above for valid values | Try it |
.modal("toggle") | Toggles the modal | Try it |
.modal("show") | Opens the modal | Try it |
.modal("hide") | Hides the modal | Try it |
Sự kiện phương thức
Bảng sau liệt kê tất cả các sự kiện phương thức có sẵn.
Event | Description | Try it |
---|---|---|
show.bs.modal | Occurs when the modal is about to be shown | Try it |
shown.bs.modal | Occurs when the modal is fully shown (after CSS transitions have completed) | Try it |
hide.bs.modal | Occurs when the modal is about to be hidden | Try it |
hidden.bs.modal | Occurs when the modal is fully hidden (after CSS transitions have completed) | Try it |
Thêm ví dụ
Phương thức đăng nhập
Ví dụ sau tạo một phương thức để đăng nhập:
Ví dụ
<div class="container">
<h2>Modal Login Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-default btn-lg" id="myBtn">Login</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 style="color:red;"><span class="glyphicon glyphicon-lock"></span> Login</h4>
</div>
<div class="modal-body">
<form role="form">
<div class="form-group">
<label for="usrname"><span class="glyphicon glyphicon-user"></span> Username</label>
<input type="text" class="form-control" id="usrname" placeholder="Enter email">
</div>
<div class="form-group">
<label for="psw"><span class="glyphicon glyphicon-eye-open"></span> Password</label>
<input type="text" class="form-control" id="psw" placeholder="Enter password">
</div>
<div class="checkbox">
<label><input type="checkbox" value="" checked>Remember me</label>
</div>
<button type="submit" class="btn btn-default btn-success btn-block"><span class="glyphicon glyphicon-off"></span> Login</button>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-default btn-default pull-left" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Cancel</button>
<p>Not a member? <a href="#">Sign Up</a></p>
<p>Forgot <a href="#">Password?</a></p>
</div>
</div>
</div>
</div>
</div>
Hãy tự mình thử »