Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Bootstrap 5 Toasts


吐司提示框

吐司提示框组件类似于警报框,仅在发生某些事件时显示几秒钟(例如,当用户点击按钮、提交表单等)。

吐司提示框标题 5 分钟前

吐司提示框主体内容


如何创建吐司提示框

要创建吐司提示框,请使用 .toast 类,并在其中添加 .toast-header.toast-body

注意: 吐司提示框默认隐藏。如果要显示它,请使用 .show 类。要关闭它,请使用 <button> 元素并添加 data-bs-dismiss="toast"

<div class="toast show">
  <div class="toast-header">
    吐司提示框标题
    <button type="button" class="btn-close" data-bs-dismiss="toast"></button>
  </div>
  <div class="toast-body">
    吐司提示框主体内容
  </div>
</div>
亲自试一试 »

打开吐司提示框

要通过点击按钮显示吐司提示框,您必须使用 JavaScript 初始化它:选择指定的元素并调用 toast() 方法。

以下代码将在您点击按钮时显示文档中的所有“吐司提示框”

示例

<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>
亲自试一试 »


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.