jQuery自定义信息提示框组件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>显示消息提示框</title>
    <style>
        .confirm .box{
            width: 70%;
            position: absolute;
            top: 50%; 
            left: 50%; 
            transform: translate(-50%, -50%);
            border-radius: 8px;
            overflow: hidden;
            text-align: center;
            color: #333;
            z-index: 999;
            background: #fff;
            display: flex;
            flex-wrap: wrap;
            font-weight: 500;
        }
        .confirm .box>div{
            width: 100%;
        }
        .confirm .box .title{
            padding-top: 10px;
        }
        .confirm .box .content{
            color: #838383;
            padding: 10px;
        }
        .confirm .box .btn{
            display: flex;
            justify-content: space-between;
            border-top: 1px solid #E2E2E2;
        }
        .confirm .box .btn>div{
            flex: 1;
            padding: 10px 0px;
            color: #1A73E8;
        }
        .confirm .box .btn div:nth-child(1){
            border-right: 1px solid #E2E2E2;
        }
        .confirm .mask{
            background: rgba(20, 20, 20, 0.8);
            position: fixed;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            border: 1px solid #333;
        }
    </style>
</head>
<body>

    <button id="pay">H5支付</button>

    <!-- <div class="confirm" >
        <div class="box">
            <div class="title">提示</div>
            <div class="content">确认要支付吗?</div>
            <div class="btn">
                <div>取消</div>
                <div>确定</div>
            </div>
        </div>
        <div class="mask"></div>
    </div> -->

    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <script>
        // 调用弹框
        function showToast(content,res,err){
            let html = $(`<div class="confirm">
                            <div class="box">
                                <div class="title">提示</div>
                                <div class="content">${content}</div>
                                <div class="btn">
                                    <div>取消</div>
                                    <div>确定</div>
                                </div>
                            </div>
                            <div class="mask"></div>
                        </div>`)
            $("body").append(html)
            $("body").on('click', '.btn',function(e){
                let text = e.target.innerText
                if(text == "确定"){
                    if ($.isFunction(res)) {
                        res()
                    }
                }else{
                    if ($.isFunction(err)) {
                        err()
                    }
                }
                $(".confirm").remove()
            })
        }


        $("#pay").click(function(){
            showToast("确认要支付吗?",function(){
                console.log("success")
            },function(){
                console.log("fail")
            })
        })


    </script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值