【问题标题】:Bootstrap using Modal where to place jquery and bootstrap when using bundleconfigBootstrap 使用 Modal 使用 bundleconfig 时放置 jquery 和 bootstrap 的位置
【发布时间】:2015-07-10 17:32:27
【问题描述】:

我将捆绑配置用于我的 jquery 和引导程序。我注意到,根据我放置 jquery 和引导程序的位置,我会得到不同的结果。

使用标准代码

@{
   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>

我想使用捆绑配置并将其添加到 _Layout 页面。

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

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

模态框会显示一秒钟然后清除,只显示褪色的背景。

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

【问题讨论】:

  • 我相信this post对你有用。
  • "并从表单中删除脚本和链接" ... ?
  • 嗨蒂姆,当我从我的 mvc 页面中删除 jquery 和 bootstrap 的“script src”和“link href”以及捆绑配置中的 jquery 和 bootstrap 并将捆绑添加到布局页面时我遇到了问题。

标签: javascript jquery css asp.net-mvc twitter-bootstrap


【解决方案1】:

这可能是因为您多次包含 Jquery 文件或引导 js 文件。我建议您检查您的捆绑配置以查看 Jquery js 文件或引导文件是否没有被多次调用。 bootstrap js 文件的多次引用可以多次实例化模态框,这可以切换其可见性并为其添加奇怪的行为。

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

【讨论】:

  • 感谢新手.... 完成了这项工作。我有多个引导程序。再次感谢您的帮助。
  • 我必须获得 15 点声望才能做到这一点。
猜你喜欢
  • 1970-01-01
  • 2016-01-02
  • 1970-01-01
  • 2018-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-24
相关资源
最近更新 更多