怎么用html及原生js实现弹窗

发布时间:2022-02-25 11:00:24 作者:iii
来源:亿速云 阅读:550

本文小编为大家详细介绍“怎么用html及原生js实现弹窗”,内容详细,步骤清晰,细节处理妥当,希望这篇“怎么用html及原生js实现弹窗”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

我们通过运用 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>

读到这里,这篇“怎么用html及原生js实现弹窗”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. 用原生js实现map的方法介绍
  2. 如何用原生js写一个弹窗消息提醒插件

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

html js

上一篇:PS怎么实现拼图

下一篇:photoshop怎么抠图换背景

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》