Bootstrap 模态加载时出现模态 UncaughtType 错误
Bootstrap modal UncaughtType Error on modal loading
我在我的项目中使用 BS 模态。我正在使用按钮打开模型,但是当我打开模式时,我在控制台中收到此错误。
错误:
modal.js:418 Uncaught TypeError: Cannot read properties of null (reading 'hide')
at HTMLButtonElement.<anonymous> (modal.js:418:23)
at HTMLDocument.s (event-handler.js:119:21)
HTML:
<div class="card my-2 mx-2 mt-4" style="width: 18rem;">
<button class="btn btn-primary" data-bs-target="#mymodal" data-bs-toggle="modal"
style="position: absolute; bottom: 0; right: 0">Get Quote</button>
</div>
模态:
<div class="modal" id="mymodal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
DO SOMETHING
</div>
</div>
</div>
</div>
我正在使用 Bootstrap5 CDN:
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
这可能是 Bootstrap5 中的错误,但我通过将 fade
class 添加到 modal
.
来解决
这是我的做法。
<div class="modal fade" id="mymodal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
DO SOMETHING
</div>
</div>
</div>
</div>
我在我的项目中使用 BS 模态。我正在使用按钮打开模型,但是当我打开模式时,我在控制台中收到此错误。
错误:
modal.js:418 Uncaught TypeError: Cannot read properties of null (reading 'hide')
at HTMLButtonElement.<anonymous> (modal.js:418:23)
at HTMLDocument.s (event-handler.js:119:21)
HTML:
<div class="card my-2 mx-2 mt-4" style="width: 18rem;">
<button class="btn btn-primary" data-bs-target="#mymodal" data-bs-toggle="modal"
style="position: absolute; bottom: 0; right: 0">Get Quote</button>
</div>
模态:
<div class="modal" id="mymodal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
DO SOMETHING
</div>
</div>
</div>
</div>
我正在使用 Bootstrap5 CDN:
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
这可能是 Bootstrap5 中的错误,但我通过将 fade
class 添加到 modal
.
这是我的做法。
<div class="modal fade" id="mymodal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
DO SOMETHING
</div>
</div>
</div>
</div>