css html js 自定义弹窗

<!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>Document</title>
    <style>
        body{
            font-size: 13pt;
        }
        #bg{
            position: absolute;
            top:0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color:rgba(0,0,0,0.5);
            display: none;            
        }
        #box{

            width: 260px;
            position: absolute;
            z-index: 2;
            left: 50%;
            margin-left: -130px;
            top:50%;
            margin-top:-75px;
                        
   
            background-color: #fff;
        }
        #box .title{
            background-color: #008081;
            color:#fff;
            padding: 10px 20px;
        }
        #box .con{
            overflow: hidden;
 
        }
        #box .con .img{
            margin: 10px;
            float: left;
     
        }
        #box .con .rright{
            float: left;
            margin-bottom: 20px;
        }
        #box .con .rright .btn{
            text-align: center;
   
        }
        #box .con .rright .btn>button{
            width: 80px;
            height: 30px;
            font-size: 20px;
            border: none;
            background-color: #008081;
            color:#fff;
        }
    </style>
</head>
<body>
    <button id="btnShow">弹框</button>
    <div id="bg">
        <!-- 定义一个弹窗 -->
        <div id="box">
            <div class="title">
                提示
            </div>
            <div class="con">
                <div class="img">
                    <img width="100px" src="img/gantanhao.png" alt="">
                </div>
                <div class="rright">
                    <p>你真的要删除吗?</p>
                    <div class="btn">
                        <button id="cls">确定</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script>
    var btnShow = document.getElementById("btnShow");
    btnShow.onclick = function(){
        var bg = document.getElementById("bg");   
        var box = document.getElementById("box");   
        bg.style.display = 'block';
        box.style.display = 'block';

    }
    var btnCls = document.getElementById("cls");
    btnCls.onclick = function(){
        bg.style.display = 'none';
        box.style.display = 'none';
    }
</script>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值