The toast component is like an alert box that is only shown for a couple of seconds when something happens (i.e. when the user clicks on a button, submits a form, etc.).
Some text inside the toast body
To create a toast, use the .toast
class, and add a .toast-header
and a .toast-body
inside of it.
Note: Toasts are hidden by default. Use the .show
class if you want to display it. To close it, use a <button> element and add data-bs-dismiss="toast"
:
<div class="toast show">
<div class="toast-header">
Toast Header
<button type="button" class="btn-close" data-bs-dismiss="toast"></button>
</div>
<div class="toast-body">
Some text inside the toast body
</div>
</div>
Try it Yourself »
To show a toast with a click of a button, you must initialize it with JavaScript: select the specified element and call the toast()
method.
The following code will show all "toasts" in the document when you click on a button:
<script>
document.getElementById("toastbtn").onclick = function() {
var toastElList = [].slice.call(document.querySelectorAll('.toast'))
var toastList = toastElList.map(function(toastEl) {
return new bootstrap.Toast(toastEl)
})
toastList.forEach(toast => toast.show())
}
</script>
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!