【问题标题】:Modal is not a function JS模态不是函数 JS
【发布时间】:2019-08-22 23:10:59
【问题描述】:

我有一个在wildfly 12上运行的页面是java EE中的一个简单项目我在eclipse neon中开发它总结我有一个基本页面并且我正在测试引导模式并且每次我尝试打开或使用方法一个js它不起作用,他告诉我modal不是一个函数,但我已经检查了很多次我的代码但我不知道它是什么

我已经尝试导入其他版本的 jquery 或引导顺序以及我如何导入它们的其他版本,但我不知道是什么

<!DOCTYPE html>
<html lang="es">

<head>

  <meta http-equiv="Content-Type" name="viewport" content="text/html , charset=utf-8" >
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="ERP online para empresas colombianas">
  <meta name="author" content="alejojau">
  <title>C-Pyme</title>

<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://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script type="text/javascript">
  $(document).ready(function() {
      $('.openBtn').on('click',function(){
            ('#myModal').modal("show");
            });
        });

  </script>
</head>

<body id="page-top">
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-success openBtn">Open Modal</button>

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">×</button>
                <h4 class="modal-title">Modal with Dynamic Content</h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>



</body>

</html>

【问题讨论】:

  • 添加脚本时在引导之前添加 jquery
  • @epascarello 仍然无法正常工作 :( 我刚刚编辑了问题以查看代码以查看 jquery 的顺序是如何再次放置的

标签: javascript html bootstrap-4 bootstrap-modal


【解决方案1】:

在引导脚本之前你必须先加载 jq 脚本

<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://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

【讨论】:

  • 仍然不工作仍然不工作:(我刚刚编辑了问题以查看代码以查看如何再次放置 jquery 的顺序
【解决方案2】:

您在modal('show') method 之前缺少$

<script type="text/javascript">
  $(document).ready(function() {
      $('.openBtn').on('click',function(){
            $('#myModal').modal("show");
            });
       });

</script>

【讨论】:

  • 谢谢朋友,我被堵得很厉害,看到是一个很简单的错误谢谢
  • 很高兴能帮上忙!! :))
猜你喜欢
  • 2014-08-15
  • 2021-09-22
  • 2016-06-19
  • 1970-01-01
  • 2022-06-17
  • 1970-01-01
  • 2018-05-11
  • 2021-03-14
  • 2022-01-25
相关资源
最近更新 更多