首页 > 解决方案 > SweetAlert 问题

问题描述

我一直在尝试在 HTML 中使用 SweetAlert,由于某种原因,它没有将 swal() 识别为函数。它只是把它作为文本放到他的页面上。我对 HTML 非常陌生,因为 Lua 和 Node.js 是我的主要语言。

这是页面上显示的内容。

swal("test", { icon: "warning", });

代码:

<html>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  swal("test", {
          icon: "warning",
        });
</html>

如果在 HTML 方面有更多经验的人能够指出我正确的方向,将不胜感激。

标签: htmlsweetalert2

解决方案


JavaScript 在 HTML 文件中时,应包含在<script></script>标签中。您还需要包含一个head部分,因此您的 HTML 将如下所示:

<html>
  <head>
    <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  </head>
  <body>
    <script>
     swal('test', {icon: 'warning'});
    </script>
  </body>
</html>

推荐阅读