Bootstrap Modal 在其他按钮上设置时未打开
Posted
技术标签:
【中文标题】Bootstrap Modal 在其他按钮上设置时未打开【英文标题】:Bootsrapmodal not opening on seting it on other button 【发布时间】:2021-10-17 22:10:47 【问题描述】:为什么当我点击登录按钮时它没有打开登录模式,但在注册时它打开了我在两者上都添加了相同的内容,只是在 eto loginModel 上重命名登录,但是在注册时它不起作用我按预期工作使用引导模式
Header.php
<button class="btn btn-success ml-2 mt-2 data-bs-toggle="modal" data-bs-target="#loginModal">login </button>
<button class="btn btn-success mx-2 mt-2" data-bs-toggle="modal" data-bs-target="#signupModal">signup </button>
</div>
</div>
</div>
</nav>';
include 'partials/_loginmodal.php';
include 'partials/_signupmodal.php';
_loginmodal.php
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" >
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="loginModal" tabindex="-1" aria-labelledby="loginModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="loginModalLabel"></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
_signupmodal.php
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" >
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="signupModal" tabindex="-1" aria-labelledby="signupModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="signupModalLabel">Signup</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
【问题讨论】:
【参考方案1】:在这一行:
<button class="btn btn-success ml-2 mt-2 data-bs-toggle="modal" data-bs-target="#loginModal">login </button>
^
缺少双引号。应该是:
<button class="btn btn-success ml-2 mt-2" data-bs-toggle="modal" data-bs-target="#loginModal">login </button>
^
【讨论】:
以上是关于Bootstrap Modal 在其他按钮上设置时未打开的主要内容,如果未能解决你的问题,请参考以下文章
在 SweetAlert2 中单击 Ok 按钮时关闭 Modal Bootstrap
bootstrap模态框背景灰色,按钮全部无法点击,求解决办法