<tfoot id='6E0s3'></tfoot>

      <small id='6E0s3'></small><noframes id='6E0s3'>

      <legend id='6E0s3'><style id='6E0s3'><dir id='6E0s3'><q id='6E0s3'></q></dir></style></legend>
        • <bdo id='6E0s3'></bdo><ul id='6E0s3'></ul>

        <i id='6E0s3'><tr id='6E0s3'><dt id='6E0s3'><q id='6E0s3'><span id='6E0s3'><b id='6E0s3'><form id='6E0s3'><ins id='6E0s3'></ins><ul id='6E0s3'></ul><sub id='6E0s3'></sub></form><legend id='6E0s3'></legend><bdo id='6E0s3'><pre id='6E0s3'><center id='6E0s3'></center></pre></bdo></b><th id='6E0s3'></th></span></q></dt></tr></i><div id='6E0s3'><tfoot id='6E0s3'></tfoot><dl id='6E0s3'><fieldset id='6E0s3'></fieldset></dl></div>

        通过单击外部关闭弹出 div

        时间:2023-10-01
            <tfoot id='51qE1'></tfoot>

            <legend id='51qE1'><style id='51qE1'><dir id='51qE1'><q id='51qE1'></q></dir></style></legend>

            <small id='51qE1'></small><noframes id='51qE1'>

              <bdo id='51qE1'></bdo><ul id='51qE1'></ul>
            • <i id='51qE1'><tr id='51qE1'><dt id='51qE1'><q id='51qE1'><span id='51qE1'><b id='51qE1'><form id='51qE1'><ins id='51qE1'></ins><ul id='51qE1'></ul><sub id='51qE1'></sub></form><legend id='51qE1'></legend><bdo id='51qE1'><pre id='51qE1'><center id='51qE1'></center></pre></bdo></b><th id='51qE1'></th></span></q></dt></tr></i><div id='51qE1'><tfoot id='51qE1'></tfoot><dl id='51qE1'><fieldset id='51qE1'></fieldset></dl></div>
                <tbody id='51qE1'></tbody>

                  本文介绍了通过单击外部关闭弹出 div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是编程的初学者.我一直在寻找答案,但我找到的答案似乎都没有解决我的问题.我使用了 如何javascript css popup div是否居中,无论屏幕分辨率如何?问题中解释的弹出div方法.

                  I am a total beginner in programming. I have been searching for an answer but none of the ones I have found seem to solve my problem. I used the how do I center javascript css popup div, no matter what the screen resolution? pop up div method explained in the question.

                  是否可以通过单击外部的 div 来关闭它,只需对以下代码进行少量更改?

                  Is it possible to close a div by clicking outside of it with small changes to the following code?

                  <script type="text/javascript">
                      function showPopUp(el) {
                          var cvr = document.getElementById("cover")
                          var dlg = document.getElementById(el)
                          cvr.style.display = "block"
                          dlg.style.display = "block"
                          if (document.body.style.overflow = "scroll") {
                              cvr.style.width = "1024"
                              cvr.style.height = "100%"
                          }
                      }
                      function closePopUp(el) {
                          var cvr = document.getElementById("cover")
                          var dlg = document.getElementById(el)
                          cvr.style.display = "none"
                          dlg.style.display = "none"
                          document.body.style.overflowY = "scroll"
                      }
                  </script>
                  <style type="text/css">
                     #cover {
                          display:        none;
                          position:       fixed;
                          left:           0px;
                          top:            0px;
                          width:          100%;
                          height:         100%;
                          background:     gray;
                          filter:         alpha(Opacity = 50);
                          opacity:        0.5;
                          -moz-opacity:   0.5;
                          -khtml-opacity: 0.5
                      }
                  
                  </style>
                  

                  在 HTML 中,我有隐藏 id 为 dialog1dialog2 等的 div 的数量.单击链接时,会显示 div 并关闭它我使用 img 链接:

                  In HTML I have the number of divs hidden with the ids dialog1, dialog2 and so on. When a link is clicked, the div shows up and to close it I use an img link:

                  < a class="close" href="#2" onclick="closePopUp('dialog2');">< img src="/img/close.png" height="30px"></a >
                  

                  推荐答案

                  当你打开弹窗时,创建一个高宽为 100% 的不可见 div,它位于你弹窗 div 的后面.

                  When you open the pop up, create an invisible div of height width 100%, which lies at the back of your pop-up div.

                  在 div 上附加一个 onclick 函数:

                  Attach an onclick function to the div:

                  document.getElementById('invisibleDiv').onclick = function()
                  {
                      document.getElementById('popup').style.display = 'none'; 
                  }
                  

                  希望有帮助

                  这篇关于通过单击外部关闭弹出 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用淘汰赛js弹出 下一篇:如何从 fetch API 返回 json 响应

                  相关文章

                1. <tfoot id='nQTvR'></tfoot>

                2. <small id='nQTvR'></small><noframes id='nQTvR'>

                    <legend id='nQTvR'><style id='nQTvR'><dir id='nQTvR'><q id='nQTvR'></q></dir></style></legend>
                      <bdo id='nQTvR'></bdo><ul id='nQTvR'></ul>

                    <i id='nQTvR'><tr id='nQTvR'><dt id='nQTvR'><q id='nQTvR'><span id='nQTvR'><b id='nQTvR'><form id='nQTvR'><ins id='nQTvR'></ins><ul id='nQTvR'></ul><sub id='nQTvR'></sub></form><legend id='nQTvR'></legend><bdo id='nQTvR'><pre id='nQTvR'><center id='nQTvR'></center></pre></bdo></b><th id='nQTvR'></th></span></q></dt></tr></i><div id='nQTvR'><tfoot id='nQTvR'></tfoot><dl id='nQTvR'><fieldset id='nQTvR'></fieldset></dl></div>