【问题标题】:Boostrap modal showing popup content on page before clicking on modal button引导模式在单击模式按钮之前在页面上显示弹出内容
【发布时间】:2015-10-08 17:42:19
【问题描述】:

尝试在此处的结帐页面上使用此模式:http://designatwork.net/c3/checkout/ 在顶部的“有医师代码?输入您的医师代码”链接下。当我放入模态代码时,它会显示应该在应该打开弹出窗口的链接下方的弹出窗口中的内容。如何让它正常工作?

<p>Don't have a Physician Code? <a data-toggle="modal" data-target="#physcode">Get one here!</a></p>
                <!-- Physician Code Modal -->
                <div class="modal-dialog">
                  <div class="modal-content">
                    <div class="modal-body">
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                      <p>AQ Skin Pro products are available exclusively through participating clinics and physicians offices. If you do not have an Exclusive Physician Code, click "generate a code" below.</p>
                      <button class="nm-simple-add-to-cart-button single_add_to_cart_button button alt" data-dismiss="modal" aria-label="Close">Generate a Code</button>
                    </div>
                  </div>
                </div>

【问题讨论】:

    标签: javascript html wordpress twitter-bootstrap


    【解决方案1】:

    您需要将模态内容包装在 &lt;div class="modal fade"&gt;&lt;/div&gt; 中,并为该包装器添加 role="dialog" 属性,如下所示:

    模态html是这样的:

     <div class="modal fade" id="physcode" tabindex="-1" role="dialog" >
             <div class="modal-dialog">
                <div class="modal-content">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
                    <h4 class="modal-title">Physician Code</h4>
                  </div>
                  <div class="modal-body">
                    <p>AQ Skin Pro products are available exclusively through participating clinics and physicians offices. If you do not have an Exclusive Physician Code, click "generate a code" below.</p>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                  </div>
                </div>
              </div>
    
         </div>
    

    触发器元素如下所示:

    <p>Don't have a Physician Code?
      <!-- Button trigger modal -->
      <a data-toggle="modal" data-target="#physcode">Get one here!</a>
    </p>
    

    【讨论】:

    • 如果您使用的是 Bootstrap 3 及更高版本,则不需要 tabindex 或角色
    【解决方案2】:

    您需要将整个内容包装在 modal div 中,还需要将其 id 设置为按钮使用的元素。试试这个代码:

    <p>Don't have a Physician Code? <a data-toggle="modal" data-target="#physcode">Get one here!</a></p>
    <div class="modal" id="physcode">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
            <h4 class="modal-title">Physician Code</h4>
          </div>
          <div class="modal-body">
            <p>AQ Skin Pro products are available exclusively through participating clinics and physicians offices. If you do not have an Exclusive Physician Code, click "generate a code" below.</p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>
    

    或者直接从我的网站拉,我使用jQuery自动打开模态,但是一个按钮仍然可以打开它。

    <div class="modal" id="modalLogin">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
                    <h4 class="modal-title">Login</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" id="formLogin" method="post" action="./index.php">
                        <fieldset>
                            <div class="form-group">
                                <label for="inputUsername" class="col-lg-2 control-label">Username</label>
                                <div class="col-lg-10">
                                    <input type="text" class="form-control" id="inputUsername" name="inputUsername" data-validation="alphanumeric length required" data-validation-allowing="-_" placeholder="User">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputPassword" class="col-lg-2 control-label">Password</label>
                                <div class="col-lg-10">
                                    <input type="password" class="form-control" id="inputPassword" name="inputPassword" data-validation="strength required" data-validation-strength="3" placeholder="Password">
                                    <span class="help-block"><a href="./index.php?p=/account/forgot">Forgot My Password</a></span>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
                <div class="modal-footer">
                    <a type="button" href="./index.php" class="btn btn-default">Cancel</a>
                    <button type="submit" class="btn btn-default" form="formLogin">Login</button>
                </div>
            </div>
        </div>
    </div>
    

    【讨论】:

    • 另外,您需要使用modal-headermodal-footer,没有它们整个模态看起来会很奇怪。
    • 我用了你的代码,没用。而且我之前已经多次使用 Bootstrap 模态,没有模态页眉或页脚。
    • 你使用的是什么版本的 Bootstrap?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多