<bdo id='JiKeF'></bdo><ul id='JiKeF'></ul>
  • <small id='JiKeF'></small><noframes id='JiKeF'>

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

    2. <tfoot id='JiKeF'></tfoot>

        在一个页面上打开多个模式框

        时间:2023-06-21
        1. <legend id='NGPF3'><style id='NGPF3'><dir id='NGPF3'><q id='NGPF3'></q></dir></style></legend>
            <tbody id='NGPF3'></tbody>
          <i id='NGPF3'><tr id='NGPF3'><dt id='NGPF3'><q id='NGPF3'><span id='NGPF3'><b id='NGPF3'><form id='NGPF3'><ins id='NGPF3'></ins><ul id='NGPF3'></ul><sub id='NGPF3'></sub></form><legend id='NGPF3'></legend><bdo id='NGPF3'><pre id='NGPF3'><center id='NGPF3'></center></pre></bdo></b><th id='NGPF3'></th></span></q></dt></tr></i><div id='NGPF3'><tfoot id='NGPF3'></tfoot><dl id='NGPF3'><fieldset id='NGPF3'></fieldset></dl></div>

            • <tfoot id='NGPF3'></tfoot>
                <bdo id='NGPF3'></bdo><ul id='NGPF3'></ul>
              • <small id='NGPF3'></small><noframes id='NGPF3'>

                  本文介绍了在一个页面上打开多个模式框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个页面,当点击页面上的相应链接时,需要打开不同的模式框.我的结构和 javascript 可以为一个窗口工作,但我不能让它为多个窗口工作.我在想我需要遍历每个模态框...但不能完全弄清楚语法.

                  I have a page that needs to have different modal boxes open when their corresponding link on the page is clicked. I've got the structure and javascript to work for ONE window, but I can't get it to work for more than one. I am thinking I need to loop through each modal box...but can't quite figure out the syntax.

                  这是针对客户的 WordPress 网站,我使用高级自定义字段来填充内容.该页面尚未发布,所以这里有一个显示我的代码的 codepen:http://codepen.io/FelixB/pen/EPvEVG

                  This is for a client's WordPress site, and I'm using Advanced Custom Fields to populate the content. The page isn't published yet, so here's a codepen that shows my code: http://codepen.io/FelixB/pen/EPvEVG

                  代码:

                  var modal = document.getElementsByClassName('modal-window');
                  
                  var btn = document.getElementsByClassName("click-to-open");
                  
                  var span = document.getElementsByClassName("close")[0];
                  
                  for (var i = 0; i < btn.length; i++) {
                    var thisBtn = btn[i]
                    thisBtn.onclick = function() {
                      alert("hello");
                  
                      //modal.style.display = "block";
                    }
                  }
                  
                  span.onclick = function() {
                    modal.style.display = "none";
                  }
                  
                  window.onclick = function(event) {
                  
                  }
                  

                  推荐答案

                  您必须使模态框独一无二,以便以后能够选择它们.一种方法是通过 id.

                  You must make modals unique to be able to select them later. One way to do this is through id.

                  <div id="modal-window-one" class="modal-window modal"></div>
                  <div id="modal-window-two" class="modal-window modal"></div>
                  

                  您需要定义哪个按钮应该打开哪个窗口.一种可能的解决方案是通过 data-attributes

                  You need to define which button which window should open. One possible solution for this is through data-attributes

                  <div class="click-to-open" data-modal="modal-window-one"> //will open modal one
                  <div class="click-to-open" data-modal="modal-window-two"> //will open modal two
                  

                  然后 - 事件:

                  var btn = document.getElementsByClassName("click-to-open");
                  
                  for (var i = 0; i < btn.length; i++) {
                    var thisBtn = btn[i];
                    thisBtn.addEventListener("click", function(){
                      var modal = document.getElementById(this.dataset.modal);
                      modal.style.display = "block";
                  }, false);
                  

                  再次 - 这是一种可能的解决方案.

                  Again - this is one possible solution.

                  这篇关于在一个页面上打开多个模式框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Javascript中的睡眠() 下一篇:“aria-hidden 元素不包含可聚焦元素"显示模态时的问题

                  相关文章

                    <bdo id='dxAtZ'></bdo><ul id='dxAtZ'></ul>
                1. <tfoot id='dxAtZ'></tfoot>

                  <legend id='dxAtZ'><style id='dxAtZ'><dir id='dxAtZ'><q id='dxAtZ'></q></dir></style></legend>

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