莫代尔没有出现

时间:2018-01-05 18:33:14

标签: jquery twitter-bootstrap

我正在使用bootstrap 4模态。但它不能正常工作,当点击按钮时,模态不会出现。它只是一个灰色的背景,然后这个背景消失了。你知道问题出在哪里吗?

//关闭标记<body>之前是导入

<script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
<link href="css/app.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/app.js"></script>

打开模态的输入位于表单内:

// html

  <input type="submit" class="btn" data-toggle="modal" data-target="#myModal" value="Send"/>
        </form>

        <div class="modal fade" id="myModal" 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>

// js

   $('#myModal').on('shown.bs.modal', function() {
        $('#myInput').focus()
    })   

1 个答案:

答案 0 :(得分:0)

如果您使用输入类型=&#34;提交&#34;显示模态您的网站将在模态显示之前重新加载。尝试更改输入类型=&#34;提交&#34;输入type =&#34; button&#34;兄弟。