javascript - 如何修复“未定义 jquery”
问题描述
我正在使用Hackernoon的教程,但出现错误:
jQuery.fn.sortDomElements = (function() { ^ ReferenceError: jQuery is not defined
在 app.js 文件中。我认为这是因为由于某种原因 app.js 和 index.html 文件没有链接在一起。在 index.html 文件中,包含了 js 文件和 jquery 脚本。(链接到 app.js 文件)
我尝试在代码中向上移动三个脚本源代码行(428-430 index.html),以确保在加载页面之前将它们包含在内,但这不起作用。
index.html 文件和 app.js 文件对我来说与示例存储库中的相同。
这是 app.js 第 8 行。
// Make a jQuery sort for the chat log based on message timetoken
(tt)
jQuery.fn.sortDomElements = (function() {
return function(comparator) {
return Array.prototype.sort.call(this,
comparator).each(function(i) {
this.parentNode.appendChild(this);
});
};
})();
解决方案
可能你丢失了一些文件,这就是它抛出错误的原因,你应该在你将使用的所有页面中包含你的 jquery
你的功能也应该是这样的
jQuery.fn.sortDomElements = (function() {
});
推荐阅读
- c - 如何在皮质 M4 上使用浮点数避免未对齐的访问异常
- macos - 绕道的 pthread_create 产生的线程不执行指令
- java - 为什么我们得到 HTTP 503 服务不可用?
- asp.net - WebAPI 中的 ExceptionFilters 永远不会被击中
- python - 将单词的部分拼接成一个新单词
- php - 在 Symfony 中使用 API Mercure 时出现问题
- android - 从 Firebase android 中的子值获取推送的 ID
- reactjs - React Js 状态不更新
- katalon-studio - 当我们在 groovy 类中定义 webdriver 工厂时遇到错误消息
- asp.net-mvc - asp.net core EF 从另一个表中获取数据