[英]Change Bootstrap Alert Class using Jquery
我的 html 表单中有警报,如下所示
<div class="alert bg-danger text-white alert-dismissible" id="alert" >
<button type="button" class="close" data-dismiss="alert"><span>×</span></button>
<span class="font-weight-semibold"><a href="#" class="alert-link" id="message">Please check your credentials</a>.
</div>
当用户提交表单时,我正在检查表单输入并根据结果我使用 jquery 更改如下所示的警报文本。
$("#error").show();
$('#error').html('Invalid EmailId or Password !');
它工作正常,但是我希望成功登录时警报类成功,我不知道如何从
alert bg-danger text-white alert-dismissible
到
alert bg-success text-white alert-dismissible
我正在尝试这样但它不起作用
$("#alert").attr("alert bg-danger text-white alert-dismissible", "alert bg-success text-white alert-dismissible");
让我知道这里是否有人可以帮助我为我解决难题。
谢谢!
使用elem.toggleClass() 。 无需更换整个班级只需在danger and success
之间切换
$("#alert").toggleClass("bg-danger bg-success");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.