Bootstrap Alert会在.hide()之后的.show()之间切换

Bootstrap Alert will toggle between .show() after .hide()

本文关键字:show 之间 之后 hide Alert Bootstrap 会在      更新时间:2023-09-26

booply Link

所以测试链接工作,然后当你点击x后,你不能切换它没有刷新页面。我做错了什么?!

警报HTML

<div class="alert alert-dismiss" id='alert' style="margin-top: 54px; margin-bottom: -54px;">
    <a href="#" class="close" data-dismiss="alert">&times;</a>
    <div class='alertMessage'></div>
</div>

警报JS:

$(function(){
    $('#updateAlert').click(function(){
        $.ajax({
            type: "GET",
            url: "update_alert.php",
            dataType: "json",
            success: function(data) {
                $("#alert").addClass(data.statusClass);
                $(".alertMessage").html(data.responseMessage);
                $(".alert").show();
            }
        });
        return false;
    });
});
$(".close").click(function(){
    $(".alert").hide();
});
$(document).ready(function(){
    $('.alert').hide();
});

Bootstrap Alert jQuery插件在关闭Alert时从DOM中移除Alert。这就是它的工作原理(故意的)。

如果你不想这样,你可以不使用data-dismiss="alert"$(...).alert('close'),或者你可以自己修改插件,使其表现不同