简体   繁体   English

Bootstrap Modal 不会出现 (ID)

[英]Bootstrap Modal Won't Appear (ID)

I have a page with 6 clickable buttons that each open up a different modal.我有一个包含 6 个可点击按钮的页面,每个按钮打开一个不同的模式。 I have 4 working ones that open their corresponding modal when clicked, however, all of them after the 4th do not work.我有 4 个工作的,在单击时会打开相应的模式,但是,第 4 个之后的所有模式都不起作用。 The modal works if I assign the ID of an existing modal to the broken modals, however, if I change ONLY the ID from portfolioModal4 to portfolioModal5, it doesn't work.如果我将现有模态的 ID 分配给损坏的模态,则模态有效,但是,如果我仅将 ID 从 portfolioModal4 更改为 portfolioModal5,则它不起作用。

Below is the code for the modal followed by the code for the button that, when pressed, should open the modal.下面是模态的代码,后面是按钮的代码,按下时应该打开模态。

 <!-- Modal 5-->
 <div class="portfolio-modal modal fade" id="portfolioModal5" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="close-modal" data-dismiss="modal"><img src="img/close-icon.svg" alt="Close modal" /></div>
                    <div class="container">
                        <div class="row justify-content-center">
                            <div class="col-lg-8">
                                <div class="modal-body">
                                    <!-- Project Details Go Here-->
                                     <h2 class="text-uppercase">Readiness Center Dedication</h2>
                                    <p class="item-intro text-muted">4 Photos</p>
                                    <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
                                      <div class="carousel-inner" role="listbox">
                                        <div class="carousel-item active">
                                          <img class="d-block w-100" src="img/chi1.jpeg" alt="First slide">
                                          <div class="carousel-caption d-none d-md-block">
                                            <div class="align-bottom">
                                              <p>Dedication Language</p>
                                            </div>
                                          </div>
                                        </div>
                                        <div class="carousel-item">
                                          <img class="d-block w-100" src="img/chi1.jpeg" alt="Second slide">
                                          <div class="carousel-caption d-none d-md-block">
                                            <div class="align-bottom">
                                              <p>Candy Mason at Renaming</p>
                                            </div>
                                          </div>

 <section class="page-section bg-light" id="portfolio">
            <div class="container">
                <div class="text-center">
                    <h2 class="section-heading text-uppercase">Photos</h2>
                    <h3 class="section-subheading text-muted"></h3>
                </div>
                <div class="row">
                    <div class="col-lg-4 col-sm-6 mb-4">
                        <div class="portfolio-item">
                            <a class="portfolio-link" data-toggle="modal" href="#portfolioModal5">
                                <div class="portfolio-hover">
                                    <div class="portfolio-hover-content"><i class="fas fa-plus fa-3x"></i></div>
                                </div>
                                <img class="img-fluid" src="img/michigan.jpg" alt="" />
                            </a>
                            <div class="portfolio-caption">
                                <div class="portfolio-caption-heading">2019 Michigan Tailgate vs. Army</div>
                                <div class="portfolio-caption-subheading text-muted">6 Photos</div>
                            </div>
                        </div>
                    </div>

Is there a reason you're using an anchor tag instead of a button to trigger your modal?您是否有理由使用锚标记而不是按钮来触发您的模态? In the Bootstrap docs , it looks like they use a button element with a data-target attribute.Bootstrap 文档中,看起来他们使用了带有 data-target 属性的按钮元素。 Can you try that instead and see if it works?你能试试看它是否有效吗? Using what they have in the docs may be more screen-reader friendly too.使用他们在文档中的内容也可能对屏幕阅读器更友好。

Seems like the part of the modal HTML is not having complete closing tags似乎模态 HTML 的部分没有完整的结束标签

Here you are a fixed HTML modal:这是一个固定的 HTML 模态:

<div class="portfolio-modal modal fade" id="portfolioModal5" tabindex="-1" role="dialog" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="close-modal" data-dismiss="modal"><img src="img/close-icon.svg" alt="Close modal" /></div>
         <div class="container">
            <div class="row justify-content-center">
               <div class="col-lg-8">
                  <div class="modal-body">
                     <!-- Project Details Go Here-->
                     <h2 class="text-uppercase">Readiness Center Dedication</h2>
                     <p class="item-intro text-muted">4 Photos</p>
                     <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
                        <div class="carousel-inner" role="listbox">
                           <div class="carousel-item active">
                              <img class="d-block w-100" src="img/chi1.jpeg" alt="First slide">
                              <div class="carousel-caption d-none d-md-block">
                                 <div class="align-bottom">
                                    <p>Dedication Language</p>
                                 </div>
                              </div>
                           </div>
                           <div class="carousel-item">
                              <img class="d-block w-100" src="img/chi1.jpeg" alt="Second slide">
                              <div class="carousel-caption d-none d-md-block">
                                 <div class="align-bottom">
                                    <p>Candy Mason at Renaming</p>
                                 </div>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </div>
</div>

I hope this would work for you我希望这对你有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM