【问题标题】:Jquery full version, 3.4, not .modal support [duplicate]Jquery 完整版,3.4,不支持 .modal [重复]
【发布时间】:2019-05-10 00:58:46
【问题描述】:

我有一个需要使用 ajax 和 cookie 的问题,所以我需要使用完整的 jquery 库。我正在使用的导入是这样的:

<script src="https://code.jquery.com/jquery-3.4.0.js"></script>

但是,我有一个模态,并且 .modal 命令在没有引导库的情况下不起作用,如下所示:

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

HTML 代码

<input type="text" name="codigoProduto" id="codigoProduto">

              <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                        </button>
                                    </div>
                                    <div class="modal-body">
                                            ...
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                        <button type="button" class="btn btn-primary">Save changes</button>
                                    </div>
                                </div>
                            </div>
                        </div> 

jQuery

$(document).ready(
$("#codigoProduto").on('dblclick',function() {        
    $("#exampleModal").modal("show");

})
);

如果我只留下 Bootstrap 库 3.3.1,代码可以正常工作。

进口:

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.4.0.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

【问题讨论】:

  • 所以使用引导版本,但不要让它变得苗条......
  • 如果我使用没有 slim 版本的 3.4 版本,.modal 命令不起作用
  • 所以使用没有 slim 的 3.3.1。虽然,tbh,引导程序可能会与 3.4 一起使用。在 3.4 版本中没有会影响引导程序的兼容性更改。您的问题可能是由于您包含 jquery 和 bootstrap 的方式,而不是您使用的版本。
  • 我在内容中添加了我正在使用的 biclotecas
  • bootstrap 不需要在 bootstrap 之前包含 jquery 吗?

标签: jquery


【解决方案1】:

您尝试在没有引导程序的情况下使用引导程序属性?如果不想使用引导程序,则不能使用data-dismiss.modal()

相反,您可以执行以下操作:

$("#exampleModal").show();

要隐藏,您可以执行以下操作:

$("exampleModal").removeAttr("style").hide();

但是大部分类都是从 bootstrap 中获取的,我不明白你为什么不想导入 bootstrap?

【讨论】:

  • 我在内容中添加了我正在使用的 biclotecas
猜你喜欢
  • 1970-01-01
  • 2017-09-20
  • 1970-01-01
  • 2013-11-25
  • 2014-01-08
  • 2014-04-24
  • 2019-07-29
相关资源
最近更新 更多