【问题标题】:progress bar is not a function进度条不是功能
【发布时间】:2026-02-09 12:10:02
【问题描述】:

在带有引导进度条的页面上出现错误:

$(...).progressbar 不是函数

正如我所见,这个错误似乎正在使我的其余脚本崩溃:

  1. Typeahead 不能在同一页面上工作 我收到以下错误:

猎犬没有定义

  1. 引导选择不起作用
  2. Web 模板不起作用

有趣的是,如果我的 enable.optimization 设置为 false,我的其余脚本不会崩溃。

下面是我的HTMLjavascript 的进度条:

function UpdateProgress(totalRecords, recordsProcessed, message) {

   var pct = recordsProcessed / totalRecords * 100;
   $('.progress-bar').css('width', pct + '%').attr('aria-valuenow', pct);

   $('#message').text(message);

   var msg = Math.round(pct, 2) + '% Complete';
   $('.progText').text(msg);

   if (pct > 0) {
     $('#progressRow').show();
   }

   if (pct == 100) {
     $('#progressRow').hide();
   }
 }


<div id="progressRow" class="row" >
  <div class="form-group">
    <div class="col-md-offset-2 col-sm-offset-2 col-md-10 col-sm-10 col-xs-12">
      <label id="message"></label>
      <div class="progress" style="height: 30px">
        <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
          <span class="progText"></span>
        </div>
      </div>
    </div>
  </div>
</div>

以下是我的bundleConfig 文件:

 bundles.Add(new ScriptBundle("~/Scripts/jquery").Include(
                "~/Scripts/jquery.min.js"
            ));

        bundles.Add(new StyleBundle("~/Content/core").Include(
            "~/Content/bootstrap.min.css",
            "~/Content/animate.min.css",
            "~/Content/custom.min.css",
            "~/Content/font-awesome.min.css",
            "~/Content/green.css",
            "~/Content/outline.button.css",
            "~/Content/bootstrap-datepicker.min.css",
            "~/Content/Pagination.css",
            "~/Content/animation.css",
            "~/Content/jBox.css",
            "~/Content/SpinnerOverLay.css",
            "~/Content/bootstrap-select.min.css",
            "~/Content/typeahead.css",
            "~/Content/icheck/square/green.css",
            "~/Content/icheck/green.css"
            ));

        bundles.Add(new StyleBundle("~/Content/login").Include(
            "~/Content/bootstrap.min.css",
            "~/Content/font-awesome.min.css",
            "~/Content/animate.min.css",
            "~/Content/custom.min.css",
            "~/Content/green.css",
            "~/Content/animation.css",
            "~/Content/jBox.css",
            "~/Content/SpinnerOverLay.css"

            ));

        bundles.Add(new ScriptBundle("~/Scripts/core").Include(
                "~/Scripts/bootstrap.min.js",
                "~/Scripts/custom.min.js",
                "~/Scripts/nprogress.min.js",
                "~/Scripts/bootstrap-datepicker.min.js",
                "~/Scripts/jquery.bpopup.min.js",
                "~/Scripts/bootstrap-select.min.js",
                "~/Scripts/typeahead.min.js",
                "~/Scripts/icheck/icheck.min.js"
            ));

        bundles.Add(new ScriptBundle("~/Scripts/login").Include(
                "~/Scripts/jquery.bpopup.min.js"
            ));

        bundles.Add(new ScriptBundle("~/Scripts/SignalR").Include(
                "~/Scripts/jquery.signalR-2.2.0.min.js"
            ));
        BundleTable.EnableOptimizations = false;

这就是cssjs 文件在masterPage 中的引用方式:

<head runat="server">
<title>Stores</title>
<%: System.Web.Optimization.Styles.Render("~/Content/core") %>

<%: System.Web.Optimization.Scripts.Render("~/Scripts/jquery") %>

    <%:System.Web.Optimization.Scripts.Render("~/Scripts/core") %>
<script src="/Scripts/notify/pnotify.buttons.min.js"></script>
<script src="/Scripts/notify/pnotify.core.min.js"></script>
<script src="/Scripts/notify/pnotify.nonblock.min.js"></script>

<script src="/Scripts/init.controls.js"></script>
<script src="/Scripts/showDisplayModalSetup.js"></script>
<script src="/Scripts/client.validation.js"></script>

【问题讨论】:

  • 您是在提到通过 bundle 加载脚本并出现错误?请详细说明这一点
  • 我正在使用 asp 优化选项 - 捆绑和缩小。所以我创建了我的包并在我的站点管理员中引用了它们。当 enable.optimization 设置为 false 时,该站点运行良好。但是一旦我启用优化,我就会面临上述情况
  • 你有最新的 jquery 和 bootstrap 版本吗? Jquery 2.2 和 Bootstrap 3.3?
  • 是的,我尝试了最新的 jquery 和 bootstrap,但效果不佳
  • 这只是顺序问题您必须正确订购css和js链接。

标签: asp.net twitter-bootstrap optimization


【解决方案1】:

我认为它工作正常。

您应该正确地包含这些库:

第一: Jquery.js

第二个: Bootstrap.js

如下图

function UpdateProgress(totalRecords, recordsProcessed, message) {

  var pct = recordsProcessed / totalRecords * 100;
  $('.progress-bar').css('width', pct + '%').attr('aria-valuenow', pct);

  $('#message').text(message);

  var msg = Math.round(pct, 2) + '% Complete';
  $('.progText').text(msg);

  if (pct > 0) {
    $('#progressRow').show();
  }

  if (pct == 100) {
    $('#progressRow').hide();
  }
}

UpdateProgress(100, 99, 'Loading')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

<div id="progressRow" class="row" >
  <div class="form-group">
    <div class="col-md-offset-2 col-sm-offset-2 col-md-10 col-sm-10 col-xs-12">
      <label id="message"></label>
      <div class="progress" style="height: 30px">
        <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
          <span class="progText"></span>
        </div>
      </div>
    </div>
  </div>
</div>

如果我遗漏了什么,请告诉我。

【讨论】:

  • 我正在使用本地引导和 jquery css 和脚本文件,它们都包含在站点主文件中。当然,如果文件没有被正确引用,引导将根本不起作用。可能是我在这里遗漏了一些东西。我添加了一个编辑问题并包含了我的站点管理员和捆绑配置文件
【解决方案2】:

由于gantellela alella 引导脚本而出现此问题:

即:

    // Progressbar
if ($(".progress .progress-bar")[0]) {
    $('.progress .progress-bar').progressbar(); // bootstrap 3
}

上面的代码抛出了错误。

【讨论】:

    【解决方案3】:

    您的代码没问题,您需要重新考虑库的顺序并添加所有必需的 .jscss 所需的文件。例如,如果您使用的是 Asp.net MVC,则按如下方式添加文件

    @Styles.Render("~/Content/bootstrap.min.css")
    

    在 _Layout.cshtml 头部

    @Scripts.Render("~/Scripts/bootstrap.min.js")
    

    &lt;/footer&gt;之后的正文中

    <script src="~/Scripts/jquery-2.1.4.min.js"></script>
    <link rel="stylesheet" href="~/Content/themes/base/jquery-ui.css" type="text/css"/>
    <script src="~/Scripts/jquery-ui-1.11.4.js"></script>
    other js files...
    

    在当前cshtml 页面的@section Scripts 部分中。

    【讨论】:

      【解决方案4】:

      我相信解决方案是使用BundleTable.Bundles.ResolveBundleUrl(),这里的回答是:ASP.NET Bundles how to disable minification

      【讨论】: