【问题标题】:How to change SweetAlert keyword from `swal` to 'swal2'如何将 SweetAlert 关键字从“swal”更改为“swal2”
【发布时间】:2017-03-09 19:09:07
【问题描述】:

您好,我一直在使用 SweetAlert,我需要 SweetAlert2 链接模式。

我不想删除 SweetAlert,因为它在我们的应用程序中被大量使用。如何将 SweetAlert2 的关键字 swal 更改为 swal2,使其不会与我们当前的 SweetAlert 插件发生冲突?

这样我就可以拥有:

swal2('Sweet Alert 2');

【问题讨论】:

  • var swal2 = swal; 在加载 SweetAlert 之前但在加载 SweetAlert2 之后似乎可以工作。

标签: javascript sweetalert sweetalert2


【解决方案1】:

这就是我所做的并且它有效:

<link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css" rel="stylesheet"/>

<button id="swal">swal</button>
<button id="swal2">swal2</button>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://unpkg.com/sweetalert2@latest/dist/sweetalert2.all.js"></script>
<script>
    var swal2 = swal;
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<script>
    $('#swal').on('click', function() { swal('Hi from swal', 'success') })
    $('#swal2').on('click', function() { swal2('Hi from swal2') })
</script>

【讨论】:

    猜你喜欢
    • 2022-08-14
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多