bootstrap alert-解散在django中不起作用



这是我的HTML代码

<div class="msg">
{% if messages %}
{% for message in messages %}
<div class="alert alert-dismissible alert-success">
<button type="button" class="close" data-dismiss="alert">
×
</button>
<strong>{{message}}</strong>
</div>
{% endfor %}
{% endif %}
</div>

消息显示表单提交后,但x按钮不工作的崩溃,如何解决它,请帮助我。

如果在引导文档中指出的默认方式不适合你,你可以尝试添加一个id到你的按钮,并使用javascript关闭它。我在我的例子中使用jQuery。还要检查您没有遗漏任何必需的cdn

$( "#alerto" ).click(function() {
$( ".alert" ).alert('close');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="msg">
{% if messages %} {% for message in messages %}
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<strong>Holy guacamole!</strong> You should check in on some of those fields below.
<button type="button" class="close" id="alerto" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
{% endfor %} {% endif %}
</div>

我在Django模板消息中有同样的bootstrap问题。我的问题是通过将这些脚本添加到模板中来解决的:

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudfare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHaiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>

你可能还想添加这个链接:

<link rel="stylesheet" href="https://bootswatch.com/4/pulse/bootstrap.min.css">

相关内容

  • 没有找到相关文章

最新更新