相关疑难解决方法(0)

Bootstrap V5 手动调用模态 myModal.show() 不起作用(vanilla javascript)

在 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)

javascript bootstrap-5

9
推荐指数
5
解决办法
2万
查看次数

标签 统计

bootstrap-5 ×1

javascript ×1