繁体   English   中英

使用Modal的Bootstrap在使用bundleconfig时在何处放置jquery和bootstrap

[英]Bootstrap using Modal where to place jquery and bootstrap when using bundleconfig

我为我的jquery和bootstrap使用bundle config。 我注意到根据放置jquery和bootstrap的位置,会得到不同的结果。

使用标准代码

@{
   ViewBag.Title = "CreateWebOrder";
}

<script src="~/Scripts/jquery-2.1.4.min.js"></script>
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/bootstrap.min.js"></script>

<h2>CreateWebOrder</h2>

<div class="container">
   <div class="row">
     <div class="col-lg-6">
        @*<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#shipToModal">Add</button>

        <!-- Button trigger modal -->
        <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
            Launch demo modal
        </button>

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

当我添加以下脚本并链接到表单顶部时,模态正常运行。

<script src="~/Scripts/jquery-2.1.4.min.js"></script>
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/bootstrap.min.js"></script>

我想使用bundle config并将其添加到_Layout页面。

当我在表单底部的_layout页面上添加我的jquery和bootstrap并从表单中删除脚本和链接时

@Scripts.Render("~/bundles/myjquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>

模态将显示一秒钟然后清除,仅显示褪色的背景。

我的问题是为什么我不能使用我的捆绑软件配置,而是将脚本和链接放在表单的顶部。 是什么导致此问题?

这可能是因为您多次包含了Jquery文件或bootstrap js文件。 我建议您检查bundle的配置,以查看是否不多次调用Jquery js文件或bootstrap文件。 bootstrap js文件的多个引用可以多次实例化模式,这可以切换其可见性并为其添加奇怪的行为。

如果这不起作用,请尝试检查您的控制台以提供一些错误信息(如果仍然存在)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM