【发布时间】:2018-05-26 04:03:42
【问题描述】:
我正在使用 Javascript 和 JQuery 等网络技术开发一个 ASP MVC Web 应用程序。
由于在我的项目中大量使用脚本,我在代码中这些脚本的正确位置和顺序方面遇到了很多问题。
确实,我的浏览器总是出错。
例如,当我按此顺序在我的 Head 标记中找到这些脚本时:
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="/template/web/js/jquery-ui.js"></script>
我会收到这些错误,指出 JQuery 的定义存在问题:
jquery.validate.min.js:16 Uncaught ReferenceError: jQuery is not 定义 在 jquery.validate.min.js:16 jquery.validate.unobtrusive.min.js:19 Uncaught ReferenceError: jQuery is not defined 在 jquery.validate.unobtrusive.min.js:19 Index:1436 Uncaught TypeError: $(...).datepicker is not a function 在 HTML 文档。 (http://localhost:60585/(S(yjivkav5ujyyjrcrznjabbqp))/Home/Index:1436:26) 在我 (http://localhost:60585/template/web/js/jquery-2.2.3.min.js:2:27151) 在 Object.fireWith [as resolveWith] (http://localhost:60585/template/web/js/jquery-2.2.3.min.js:2:27914) 在 Function.ready (http://localhost:60585/template/web/js/jquery-2.2.3.min.js:2:29707) 在 HTMLDocument.J (http://localhost:60585/template/web/js/jquery-2.2.3.min.js:2:29892)
但是当我尝试像这样在页面底部找到所有这些脚本时:
<script src="/template/web/js/jquery-ui.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
会出现这些错误:
未捕获的类型错误:$(...).ziehharmonika 不是函数 在 HTML 文档。 (http://localhost:60585/(S(ls4ko4ghxnphalf2azyphinz))/Home/Index:1462:23) 在我 (http://localhost:60585/template/web/js/jquery-2.2.3.min.js:2:27151) 在 Object.fireWith [as resolveWith] (http://localhost:60585/template/web/js/jquery-2.2.3.min.js:2:27914) 在 Function.ready (http://localhost:60585/template/web/js/jquery-2.2.3.min.js:2:29707) 在 HTMLDocument.J (http://localhost:60585/template/web/js/jquery-2.2.3.min.js:2:29892) 索引:1441 未捕获的类型错误:$(...).JiSlider 不是函数 在http://localhost:60585/(S(ls4ko4ghxnphalf2azyphinz))/Home/Index:1441:20 调度时 (http://localhost:60585/template/web/js/jquery-2.2.3.min.js:3:7537) 在 r.handle (http://localhost:60585/template/web/js/jquery-2.2.3.min.js:3:5620)
【问题讨论】:
-
不是块的位置,是顺序。你在 需要它的脚本之后加载 jQuery。修正订单。
-
@SamiKuhmonen 感谢您的回复。是的,我也想知道正确的顺序。我不知道哪个先来,哪个最后
标签: javascript jquery