sweetalert完整例子

以下是几种sweet other的弹窗的图片代码在图片最后面         给个赞,给个关注吧

一般弹窗

689921e88dee4776bb3a58bbd04b0e05.jpg

 正确

c32f572d7d7247b0ba51d16e27acd40b.jpg

 错误16d5f1d86c9949ee963648802d41fd86.jpg

 信息

cb79e8681b66497cbc79bb863b53dce6.jpg

 警告

c340357c2c374af18544f206f4eff5a9.jpg

 自定义图片

966eb6a557df4327bd6c571e59b809af.jpg

 输入338202bbc2c147e7bec5c38ebe72132d.jpg

 

以下是完整例子的源代码,这段代码在干什么可以看我用粗体加重的注释

<!DOCTYPE html>
<html>
<head>
    <title>SweetAlert Examples</title>
    <!-- 引入SweetAlert库 -->
    <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
</head>
<body>

<h2>SweetAlert Examples</h2>

<!-- 基本警告 -->
<button οnclick="basicAlert()">Basic Alert</button>
<script>
    function basicAlert() {
        swal("Hello, world!");
    }
</script>

<!-- 成功消息 -->
<button οnclick="successMessage()">Success Message</button>
<script>
    function successMessage() {
        swal("Good job!", "You clicked the button!", "success");
    }
</script>

<!-- 错误消息 -->
<button οnclick="errorMessage()">Error Message</button>
<script>
    function errorMessage() {
        swal("Oops...", "Something went wrong!", "error");
    }
</script>

<!-- 信息消息 -->
<button οnclick="infoMessage()">Info Message</button>
<script>
    function infoMessage() {
        swal("Just a moment!", "Loading your order...", "info");
    }
</script>

<!-- 警告确认 -->
<button οnclick="warningConfirmation()">Warning Confirmation</button>
<script>
    function warningConfirmation() {
        swal({
            title: "Are you sure?",
            text: "Once deleted, you will not be able to recover this imaginary file!",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        })
        .then((willDelete) => {
            if (willDelete) {
                swal("Poof! Your imaginary file has been deleted!", {
                    icon: "success",
                });
            } else {
                swal("Your imaginary file is safe!");
            }
        });
    }
</script>

<!-- 自定义图标 -->
<button οnclick="customIcon()">Custom Icon</button>
<script>
    function customIcon() {
        swal({
            title: "Nice!",
            text: "Here's a custom image.",
            icon: "https://unsplash.it/200/300",
            timer: 2000,
        });
    }
</script>

<!-- 输入字段 -->
<button οnclick="inputField()">Input Field</button>
<script>
    function inputField() {
        swal({
            content: {
                element: "input",
                attributes: {
                    placeholder: "Type your username",
                    type: "text",
                },
            },
            button: {
                text: "Submit",
                closeModal: false,
            },
        })
        .then((value) => {
            if (value) {
                swal(`Username: ${value}`);
            } else {
                swal("Cancelled");
            }
        });
    }
</script>

</body>
</html>

 

  • 19
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值