【问题标题】:Uncaught TypeError: $(...).draggable is not a function error in ASP .NET MVC View fileUncaught TypeError: $(...).draggable is not a function error in ASP .NET MVC View file
【发布时间】:2017-03-21 07:22:34
【问题描述】:

Uncaught TypeError: $(...).draggable is not a function 是错误。 所有必需的文件都已按顺序添加。 尝试清除缓存和所有这些东西,但仍然无法正常工作。我可能正在做一些愚蠢的事情还是我错过了什么。 我尝试从许多来源添加 CDN,直接使用来源中的文件但没有效果。使用 Id 'draggable' 而不是类。有人可以帮忙吗 这是更新的代码 `

 <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

    <script src="~/Scripts/jquery-1.12.4.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script>
      $( function() {
          $(".draggable").draggable();
      } );
    </script>
     <div class="draggable col-md-6">Test</div>

` 更新:

代码在 MVC 项目的 Views 文件夹中的索引文件中运行。我不知道这些信息是否有用

【问题讨论】:

  • 没有发现上述代码有任何问题。你确定你只有这么多代码吗?否则分享完整的代码。
  • 这么多信息还不够,不是我有任何问题要展示,而是它只是一个普通的 html 索引页面,我认为不会对 js 产生任何影响

标签: jquery .net asp.net-mvc jquery-ui


【解决方案1】:

您的代码运行良好。

$(function() {
  $(".draggable").draggable();
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<div class="draggable col-md-6">Test</div>

【讨论】:

  • 感谢您尝试这个,但问题不是代码
【解决方案2】:

draggable 拼写错误,也应该用 .而不是#只要是一个类,而不是一个ID。试试这个代码:

 <style>
        .draggable {
            width: 150px;
            height: 150px;
            padding: 0.5em;
            background-color: red;
        }
    </style>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script>
      $( function() {
          $(".draggable").draggable();
      } );
    </script>
     <div class="draggable">
      Hola
     </div>

【讨论】:

  • 我不认为更正 CSS 会解决这里的问题。(无论如何都试过了)。但是thanx尝试,问题是别的。事实上,这里不需要 CSS。
  • 尝试按照我放置的方式加载库。在许多浏览器中,如果您在声明加载之前有一个对象,它就会失败。
【解决方案3】:

问题是在 ASP .NET MVC 中有一个默认的代码行

@RenderSection("scripts", required: true)

禁用视图中的所有其他脚本 要解决这个问题,只需在脚本部分中添加脚本文件即可

@section scripts {
<script src="~/Scripts/jquery-ui-1.12.1.js"></script>
}

希望它对未来的人有所帮助。

【讨论】:

    【解决方案4】:

    就我而言,

    页面指的是 - 两个 jquery.js 引用。

    一个在母版页中。 (布局页面)与旧版本。并在正文页脚处。

    所以我删除了旧版本,并在标题部分给出了对新版本的引用。

    【讨论】:

      猜你喜欢
      • 2020-03-25
      • 2017-08-01
      • 2017-04-13
      • 1970-01-01
      • 2015-09-07
      • 2018-12-13
      • 1970-01-01
      • 2015-09-18
      • 2020-03-17
      相关资源
      最近更新 更多