jquery实现告警框(可关闭)

 

... ...
<div class="container">

    <div id="myAlert" class="alert alert-success alert-dismissible" role="alert" style="display: none">
        <button type="button" class="close">×</button>
        <strong>成功!</strong> <span id="success"></span>
    </div>

    <div id="myAlert2" class="alert alert-danger alert-dismissible" role="alert" style="display: none">
        <button type="button" class="close">×</button>
        <strong style="color: red">错误!</strong> <span id="error"></span>
    </div>
   ... ...

</div> <!-- /container -->
... ...

<script>
    $(document).ready(function () {
        $("#about").click(function () {
            $.getJSON("{{ url_for('init.data') }}", function (data, status) {

                if (data.status == "ok") {
                    $("#myAlert").show();
                    $("#success").text(data.message);
                } else if (data.status == "error") {
                    $("#myAlert2").show();
                    $("#error").text(data.message);
                }
                {#alert("数据: " + data + "\n状态: " + status);#}
            });
        });
        $(".close").click(function () {
            $("#myAlert").hide();
            $("#myAlert2").hide();
        })
    });
</script>

  

posted @ 2022-02-16 22:15  Linuxbugs  阅读(136)  评论(0编辑  收藏  举报