1. 程式人生 > 其它 >jquery實現告警框(可關閉)

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>

  

轉載請標明出處:http://www.cnblogs.com/duzhaoqi/