在 bootstrap 5 中手动调用模态的正确方法是什么?
我想在页面打开时显示模态。我试过这个:
我的模态
<div class="modal fade" id="myModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
...
...
...
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的脚本是
var myModal = document.getElementById('myModal');
document.onreadystatechange = function() {
myModal.show();
}
Run Code Online (Sandbox Code Playgroud)
但在控制台日志中出现此错误:
myModal.show is not a function
at HTMLDocument.document.onreadystatechange
Run Code Online (Sandbox Code Playgroud)