模态不是函数JS

时间:2019-08-22 14:54:12

标签: javascript html bootstrap-4 bootstrap-modal

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

我已经尝试导入其他版本的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>

2 个答案:

答案 0 :(得分:0)

您必须在引导脚本之前先加载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>

答案 1 :(得分:0)

您在$之前错过了modal('show') method

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

</script>