关闭Bootstrap Alert之前的链接

时间:2015-11-13 18:39:50

标签: javascript jquery twitter-bootstrap

我正在尝试关闭之后的警告我点击其中的链接,然后我们点击链接。发生的事情是警报正在关闭而没有关注链接:

<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事件的解决方案。

1 个答案:

答案 0 :(得分:1)

你应该能够加入引导事件并且它并不复杂。来自文档:bootstrap alerts。它需要一个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>