gpt4 book ai didi

javascript - 在函数调用时打开模态

转载 作者:行者123 更新时间:2023-11-29 20:27:07 25 4
gpt4 key购买 nike

我有一个带有函数示例的 js 文件。我在下面的另一个函数中调用该函数。我现在需要的是在不单击按钮的情况下打开我的模式。它在单击按钮时完美运行,但在我的情况下这不是我所需要的。任何解决方案如何在不单击此按钮的情况下在函数调用中显示此模式?

function Example() {

return (
<>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</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">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<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">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</>
);
}


最佳答案

$("#exampleModal").modal('show');

尝试在显示模态的函数中调用它。也不要忘记导入 . jquery 在调用此函数之前。您可以在主页中导入 jquery,一切都会正常工作

关于javascript - 在函数调用时打开模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59048984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com