除了通過自定義data-dismiss="alert"
屬性來觸發(fā)警告框關(guān)閉之外,還可以通過JavaScript方法。只需要在關(guān)閉按鈕上綁定一個事件。如下所示:
html代碼:
<div class="alert alert-warning" role="alert" id="myAlert"> <h4>謹(jǐn)防被騙</h4> <p>請確認(rèn)您轉(zhuǎn)賬的信息是你的親朋好友,不要輕意相信不認(rèn)識的人...</p> <button type="button" class="btn btn-danger" id="close">關(guān)閉</button> </div>
通過下面的JavaScript代碼來觸發(fā):
$(function(){ $("#close").on("click",function(){ $(this).alert("close"); }); });
運(yùn)行效果如下:
我來試試:補(bǔ)充右側(cè)JS代碼完成使用JS關(guān)閉警告框的功能。
<script>
$(function(){
$("#close").on("click",function(){
$(this).alert("close");
});
});
</script>
請驗(yàn)證,完成請求
由于請求次數(shù)過多,請先驗(yàn)證,完成再次請求
打開微信掃碼自動綁定
綁定后可得到
使用 Ctrl+D 可將課程添加到書簽
舉報(bào)