警告框--JavaScript触发警告框

xiaoxiao2021-02-28  97

除了通过自定义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"); }); });

运行效果如下:

转载请注明原文地址: https://www.6miu.com/read-49004.html

最新回复(0)