查询SweetAlert Simple消息框

时间:2016-07-16 14:18:24

标签: jquery sweetalert

我是jQuery的新手,我也是Sweet警报的新手,我看到了使用甜蜜警报的基本警报,并尝试在我的代码中执行此操作,但它无法正常工作。 有人可以告诉我为什么它不起作用......

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
        <script src="sweetalert-master/dist/sweetalert.min.js"></script>
        <link rel="sweetalert-master/dist/sweetalert.css">
    </head>
    <body>      
        <script>
        $('.show-alert').on('click', function ()
        {
            sweetAlert('Replace Default Alerts');
        });
        </script>
        <a href="#" class="show-alert">Show Alert</a>

    </body>
</html>

提前致谢!!!

1 个答案:

答案 0 :(得分:1)

您的代码中的兴趣点是:

  1. SweetAlert的路径包含路径可能有误。您可以使用:
  2. https://rawgit.com/t4t5/sweetalert/master/dist/sweetalert.min.js

    https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js

    1. 有必要在文件就绪时调用sweetAlert(参见:document ready),否则dom元素尚未准备好使用。
    2. 所以代码片段是:

      $(function () {
        $('.show-alert').on('click', function(e) {
          e.preventDefault();
          sweetAlert('Replace Default Alerts');
        });
      });
      <link rel="stylesheet" href="https://rawgit.com/t4t5/sweetalert/master/dist/sweetalert.css">
      <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
      <script src="https://rawgit.com/t4t5/sweetalert/master/dist/sweetalert.min.js"></script>
      
      
      <a href="#" class="show-alert">Show Alert</a>