关闭Bootstrap Alert之前请遵循链接

Following link before closing Bootstrap Alert

本文关键字:链接 Bootstrap Alert 关闭      更新时间:2023-09-26

我试图在之后关闭一个警报。我单击其中的链接,然后按照链接进行操作。正在发生的情况是警报正在关闭,而没有遵循以下链接:

<div role="alert" class="alert alert-warning alert-dismissible">
    <button aria-label="Close" data-dismiss="alert" class="close" type="button"><span aria-hidden="true">×</span></button>
    A response has been updated. <a data-dismiss="alert" href="#main">Click here to view the update.</a>
</div>

如果可能的话,我正在寻找一种不需要大量连接Javascript事件的解决方案。

您应该能够挂接引导程序事件,它并没有那么复杂。来自文档:引导程序警报。它需要一个id或相应的警报选择器。

html

<div role="alert" class="alert alert-warning alert-dismissible" id="myAlert">
    <button aria-label="Close" data-dismiss="alert" class="close" type="button">
    <span aria-hidden="true">×</span></button>
    A response has been updated. <a data-dismiss="alert" href="#main">Click here to view the update.</a>
</div>

js

<script>
    $('#myAlert').on('closed.bs.alert', function () {
        window.location.href = "http://www.google.com";
    })
</script>