我在我的web应用程序中使用了bootstrap 5,但没有显示模式。
下面是我的模式和激活它的按钮的HTML:
<div
class="modal"
tabindex="-1"
id="newInstallModal"
aria-labelledby="settings"
>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">
<p>Modal body text goes here.</p>
</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>
<input
id="newInstallButton"
type="button"
class="btn btn-outline-primary"
value="New Install"
/>下面是赋值bootstrap-5以通过js打开模式的typescript代码。
newInstallModal = <HTMLDivElement>document.getElementById("newInstallModal");
newInstallButton = <HTMLButtonElement>document.getElementById("newInstallButton");
newInstallModal.addEventListener("show.bs.modal", () => {
newInstallButton.focus();
})任何帮助都是好的,因为我今天已经完成了调试。
发布于 2021-06-03 15:05:40
Bootstrap模式v5 usage
您必须使用data-属性:
<button type="button" data-bs-toggle="modal" data-bs-target="#newInstallModal">Launch modal</button>或者通过脚本:
var myModal = new bootstrap.Modal(document.getElementById('newInstallModal'), options)编辑:同时
myModal.addEventListener('shown.bs.modal', ...)只是一个事件侦听器,用于显示模式时(显示转换结束后)
https://stackoverflow.com/questions/67813660
复制相似问题