简单前端弹窗小案例分享!

猿友 2021-07-29 14:11:05 浏览数 (2359)
反馈

在程序运行中的报错我们都会收到相关错误弹窗的警告,那么今天小编就和大家分享个“简单前端弹窗小案例分享! ”相关内容分享!

我们通过运用 html 及原生 js 写个弹窗,供参考。

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8" />
  <title></title>
  <style type="text/css">
   body{
    margin: 0px;
   }
   .zhezhao{
    position: fixed;
    left: 0px;
    top: 0px;
    background: #000;
    width: 100%;
    height: 100%;
    opacity: 0.5;
   }
   .tankuang{
    position: relative;
    background: #fff;
    width: 50%;
    height: 80%;
    border-radius: 5px;
    margin: 5% auto;
   }
   #header{
    height: 40px;
   }
   #header-right{
    position: absolute;
    width: 25px;
    height: 25px;
    border-radius: 5px;
    background: red;
    color: #fff;
    right: 5px;
    top: 5px;
    text-align: center;
   }
  </style>
 </head>
 <body>
  <button type="button" onclick="dianwo()">点我</button>
  <div class="zhezhao" id='zhezhao'>
   <div class="tankuang">
    <div id="header">
     <span>我是弹窗</span>
     <div id="header-right" onclick="hidder()">x</div>
    </div>
   </div>
  </div>
  <script type="text/javascript">
   document.getElementById('zhezhao').style.display="none";
   function dianwo(){
    document.getElementById('zhezhao').style.display="";
   }
   function hidder(){
    document.getElementById('zhezhao').style.display="none";
   }
  </script>
 </body>
</html>

以上就是小编自己编写的有关于“简单前端弹窗小案例分享! ”这方面的相关内容分享,当然了实现的方法肯定不只有一种,有感兴趣的小伙伴们可以在W3Cschool中进行全面的学习! 


0 人点赞