HTML 模态窗口在按钮点击时未显示,并在隐藏时影响其他元素位置。

huangapple go评论60阅读模式
英文:

HTML Modal not showing when button is clicked, and is displacing other elements when hidden

问题

我不确定哪里出错了。这是我第一次使用模态框,但允许用户使用该服务是必要的。我正在遵循bootstraps教程的模态框,这也是为什么目前它们是样板。当单击“注册”按钮时,我无法让它显示。

现在模态框正在移动所有当前的HTML元素,但是当单击按钮时不会显示。

<section>
    <div class="page-header min-vh-100">
      <div class="container">
        <div class="row">
          <div class="col-xl-4 col-lg-5 col-md-7 d-flex flex-column mx-lg-0 mx-auto">
            {{ form.csrf_token }}
              <div id="login-card" class="card card-plain">
                <div class="card-header pb-0 text-left">
                  <h4 class="font-weight-bolder">欢迎回来</h4>
                  <p class="mb-0">登录以开始探索Fellos播客生成器</p>
                </div>
                <div id="signincard" class="card-body">
                  
                  <div id="emaildiv">
                    {{form.email}}
                  </div>

                  <div id="passworddiv">
                    {{form.password}}
                  </div>
                  <input class="btn btn-lg bg-gradient-primary btn-lg w-100 mt-4 mb-0" id="login-button" name="submit" type="button" value="登录" data-clipboard-target="#query">

                  <div id="forgot_or_signup">
                    <button id="forgotpass" type="button">忘记密码?</button>
                    <button id="sign_up" type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
                      注册!
                    </button>
                    <!-- 模态框 -->
                    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                      <div class="modal-dialog" role="document">
                        <div class="modal-content">
                          <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLabel">模态框标题</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="关闭">
                              <span aria-hidden="true">&times;</span>
                            </button>
                          </div>
                          <div class="modal-body">
                            ...
                          </div>
                          <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary">保存更改</button>
                          </div>
                        </div>
                      </div>
                    </div>
                    
               
                </div>
                
              </div>
          
          <div class="col-6 d-lg-flex d-none h-100 my-auto pe-0 position-absolute top-0 end-0 text-center justify-content-center flex-column">
            <div class="position-relative h-100 m-3 px-7 border-radius-lg d-flex flex-column justify-content-center" style="background-color: black;">
              <img src="{{ url_for('static', filename='assets/img/shapes/pattern-lines.svg') }}" alt="pattern-lines" class="position-absolute opacity-8 start-0">
              <div class="position-relative mt-6">
                <img class="max-width-500 w-100 position-relative z-index-2" src="{{ url_for('static', filename='assets/img/WELLFOUND_EMBLEM_WHITE.png') }}" alt="image">
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>
英文:

I am not sure where I am going wrong. This is my first time working with modals, but it is necessary to allow my users to sign up with the service. I am following bootstraps tutorial for modals hence why they are boilerplate at the moment. I am not able to get it to show when the "Sign Up" button is clicked.

As it stands the modal is moving all my current html elements around, but will not show when the button is clicked.

&lt;section&gt;
    &lt;div class=&quot;page-header min-vh-100&quot;&gt;
      &lt;div class=&quot;container&quot;&gt;
        &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-xl-4 col-lg-5 col-md-7 d-flex flex-column mx-lg-0 mx-auto&quot;&gt;
            {{ form.csrf_token }}
              &lt;div id=&quot;login-card&quot; class=&quot;card card-plain&quot;&gt;
                &lt;div class=&quot;card-header pb-0 text-left&quot;&gt;
                  &lt;h4 class=&quot;font-weight-bolder&quot;&gt;Welcome back&lt;/h4&gt;
                  &lt;p class=&quot;mb-0&quot;&gt;Sign in to start exploring Fellos&#39; podcast builder&lt;/p&gt;
                &lt;/div&gt;
                &lt;div id=&quot;signincard&quot; class=&quot;card-body&quot;&gt;
                  
                  &lt;div id=&quot;emaildiv&quot;&gt;
                    {{form.email}}
                  &lt;/div&gt;

                  &lt;div id=&quot;passworddiv&quot;&gt;
                    {{form.password}}
                  &lt;/div&gt;
                  &lt;input class=&quot;btn btn-lg bg-gradient-primary btn-lg w-100 mt-4 mb-0&quot; id=&quot;login-button&quot; name=&quot;submit&quot; type=&quot;button&quot; value=&quot;Sign In&quot; data-clipboard-target=&quot;#query&quot;&gt;

                  &lt;div id=&quot;forgot_or_signup&quot;&gt;
                    &lt;button id=&quot;forgotpass&quot; type=&quot;button&quot;&gt;Forgot Password?&lt;/button&gt;
                    &lt;button id=&quot;sign_up&quot; type=&quot;button&quot; class=&quot;btn btn-primary&quot; data-toggle=&quot;modal&quot; data-target=&quot;#exampleModal&quot;&gt;
                      Sign Up!
                    &lt;/button&gt;
                    &lt;!-- Modal --&gt;
                    &lt;div class=&quot;modal fade&quot; id=&quot;exampleModal&quot; tabindex=&quot;-1&quot; role=&quot;dialog&quot; aria-labelledby=&quot;exampleModalLabel&quot; aria-hidden=&quot;true&quot;&gt;
                      &lt;div class=&quot;modal-dialog&quot; role=&quot;document&quot;&gt;
                        &lt;div class=&quot;modal-content&quot;&gt;
                          &lt;div class=&quot;modal-header&quot;&gt;
                            &lt;h5 class=&quot;modal-title&quot; id=&quot;exampleModalLabel&quot;&gt;Modal title&lt;/h5&gt;
                            &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot; aria-label=&quot;Close&quot;&gt;
                              &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
                            &lt;/button&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;modal-body&quot;&gt;
                            ...
                          &lt;/div&gt;
                          &lt;div class=&quot;modal-footer&quot;&gt;
                            &lt;button type=&quot;button&quot; class=&quot;btn btn-secondary&quot; data-dismiss=&quot;modal&quot;&gt;Close&lt;/button&gt;
                            &lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot;&gt;Save changes&lt;/button&gt;
                          &lt;/div&gt;
                        &lt;/div&gt;
                      &lt;/div&gt;
                    &lt;/div&gt;
                    
               
                &lt;/div&gt;
                
              &lt;/div&gt;
          
          &lt;div class=&quot;col-6 d-lg-flex d-none h-100 my-auto pe-0 position-absolute top-0 end-0 text-center justify-content-center flex-column&quot;&gt;
            &lt;div class=&quot;position-relative h-100 m-3 px-7 border-radius-lg d-flex flex-column justify-content-center&quot; style=&quot;background-color: black;&quot;&gt;
              &lt;img src=&quot;{{ url_for(&#39;static&#39;, filename=&#39;assets/img/shapes/pattern-lines.svg&#39;) }}&quot; alt=&quot;pattern-lines&quot; class=&quot;position-absolute opacity-8 start-0&quot;&gt;
              &lt;div class=&quot;position-relative mt-6&quot;&gt;
                &lt;img class=&quot;max-width-500 w-100 position-relative z-index-2&quot; src=&quot;{{ url_for(&#39;static&#39;, filename=&#39;assets/img/WELLFOUND_EMBLEM_WHITE.png&#39;) }}&quot; alt=&quot;image&quot;&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/section&gt;

答案1

得分: 1

如果您使用 Bootstrap 5.3,则需要更改以下属性。

在注册按钮中,将data-toggle更改为data-bs-toggle

<button id="sign_up" type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal"> Sign Up! </button>

以及模态框的关闭按钮,将data-dismiss更改为data-bs-dismiss

<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">
  <span aria-hidden="true">&times;</span>
</button>

<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
英文:

If you are using bootstrap 5.3 then you need to change this attributes.

in sign up button, change this data-toggle in to this data-bs-toggle

&lt;button id=&quot;sign_up&quot; type=&quot;button&quot; class=&quot;btn btn-primary&quot; data-bs-toggle=&quot;modal&quot; data-bs-target=&quot;#exampleModal&quot;&gt; Sign Up! &lt;/button&gt;

as will as the close button of the modal from data-dismiss to data-bs-dismiss

&lt;button type=&quot;button&quot; class=&quot;btn-close&quot; data-bs-dismiss=&quot;modal&quot; aria-label=&quot;Close&quot;&gt;
                              &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
                            &lt;/button&gt;

&lt;button type=&quot;button&quot; class=&quot;btn btn-secondary&quot; data-bs-dismiss=&quot;modal&quot;&gt;Close&lt;/button&gt;

Test this in your own.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;head&gt;
  &lt;meta charset=&quot;utf-8&quot;&gt;
  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ&quot; crossorigin=&quot;anonymous&quot;&gt;
  &lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js&quot; integrity=&quot;sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
  &lt;section&gt;
    &lt;div class=&quot;page-header min-vh-100&quot;&gt;
      &lt;div class=&quot;container&quot;&gt;
        &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-xl-4 col-lg-5 col-md-7 d-flex flex-column mx-lg-0 mx-auto&quot;&gt;
            {{ form.csrf_token }}
            &lt;div id=&quot;login-card&quot; class=&quot;card card-plain&quot;&gt;
              &lt;div class=&quot;card-header pb-0 text-left&quot;&gt;
                &lt;h4 class=&quot;font-weight-bolder&quot;&gt;Welcome back&lt;/h4&gt;
                &lt;p class=&quot;mb-0&quot;&gt;Sign in to start exploring Fellos&#39; podcast builder&lt;/p&gt;
              &lt;/div&gt;
              &lt;div id=&quot;signincard&quot; class=&quot;card-body&quot;&gt;

                &lt;div id=&quot;emaildiv&quot;&gt;
                  {{form.email}}
                &lt;/div&gt;

                &lt;div id=&quot;passworddiv&quot;&gt;
                  {{form.password}}
                &lt;/div&gt;
                &lt;input class=&quot;btn btn-lg bg-gradient-primary btn-lg w-100 mt-4 mb-0&quot; id=&quot;login-button&quot; name=&quot;submit&quot; type=&quot;button&quot; value=&quot;Sign In&quot; data-clipboard-target=&quot;#query&quot;&gt;

                &lt;div id=&quot;forgot_or_signup&quot;&gt;
                  &lt;button id=&quot;forgotpass&quot; type=&quot;button&quot;&gt;Forgot Password?&lt;/button&gt;
                  &lt;button id=&quot;sign_up&quot; type=&quot;button&quot; class=&quot;btn btn-primary&quot; data-bs-toggle=&quot;modal&quot; data-bs-target=&quot;#exampleModal&quot;&gt;
                          Sign Up!
                        &lt;/button&gt;

                  &lt;!-- Modal --&gt;
                  &lt;div class=&quot;modal fade&quot; id=&quot;exampleModal&quot; tabindex=&quot;-1&quot; aria-labelledby=&quot;exampleModalLabel&quot; aria-hidden=&quot;true&quot;&gt;
                    &lt;div class=&quot;modal-dialog&quot; role=&quot;document&quot;&gt;
                      &lt;div class=&quot;modal-content&quot;&gt;
                        &lt;div class=&quot;modal-header&quot;&gt;
                          &lt;h5 class=&quot;modal-title&quot; id=&quot;exampleModalLabel&quot;&gt;Modal title&lt;/h5&gt;
                          &lt;button type=&quot;button&quot; class=&quot;btn-close&quot; data-bs-dismiss=&quot;modal&quot; aria-label=&quot;Close&quot;&gt;
                                  &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
                                &lt;/button&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;modal-body&quot;&gt;
                          ...
                        &lt;/div&gt;
                        &lt;div class=&quot;modal-footer&quot;&gt;
                          &lt;button type=&quot;button&quot; class=&quot;btn btn-secondary&quot; data-bs-dismiss=&quot;modal&quot;&gt;Close&lt;/button&gt;
                          &lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot;&gt;Save changes&lt;/button&gt;
                        &lt;/div&gt;
                      &lt;/div&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;

              &lt;/div&gt;

            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
  &lt;/section&gt;
&lt;/body&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年4月4日 05:18:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75923848.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定