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