如何检查是否显示了引导模式

问题描述

出于热爱,我阅读了许多帖子(12 ...),但仍然无法解决这个简单的问题:

我有一个按钮,它使用 htmx 打开一个模式:

<button class="btn btn-primary" 
        id="createButton"
        hx-get="/create" 
        hx-target="#modals-here">create
</button>

我的模态看起来像这样,并且可以完美地打开和运行:

<div id="modal-backdrop" class="modal-backdrop fade show" style="display:block;"></div>
<div id="modalCreate" class="modal fade show" tabindex="-1" style="display:block;">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-body">
                {% csrf_token %}
                {% crispy form %}
            </div>
        </div>
    </div>
</div>

在我页面的某个地方,我有一个 <div id="modals-here"></div>在这个模式中,有一些我想验证的输入字段。为此,了解模态何时打开将非常有用。我试过了:

$('#modalCreate').on('shown',function (event) {
//('#modalCreate').on('show.bs.modal',function (event) {
    console.log("hello");
});

这是我的 base.html(对于包含):

{% block javascript %}

    <!-- jQuery -->            
    <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="..." crossorigin="anonymous"></script>
       
    <!-- Bootstrap JavaScript -->
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="..." crossorigin="anonymous"></script> 
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="..." crossorigin="anonymous"></script>
        
    <!-- htmx -->
    <script src="{% static 'js/htmx.min.js' %}"></script>

    <!-- crispy validator -->
    <script src="{% static 'js/crispy_validator.js' %}"></script>

{% endblock javascript %}

我需要一种可靠的方法来确定我的模态是否/哪个处于活动状态。 hello 永远不会出现在控制台中。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)