Post by account_disabled on Dec 12, 2023 1:02:51 GMT -5
无论您是否熟悉WordPress 错误,在网站上工作时遇到“jQuery 未定义”从来都不是一件有趣的事情。它可能是突然出现并造成一些混乱的消息。幸运的是,这是一个标准错误,任何使用 jQuery 的网站迟早都会遇到它。 也许您的网站已经崩溃,当您检查浏览器控制台是否有错误时,您会看到“jQuery 未定义”。 找到错误是第一步,太棒了! 下一步是修复它。这是最容易修复的JavaScript错误之一,因此它不会占用您太多时间。 在本文中,我们将了解快速修复该问题所需了解的所有内容。这包括错误的含义、可能发生的原因以及防止将来再次出现该错误的任何重要信息。最后,我们将看看采取什么步骤来解决它。 开始吧! 观看我们的视频指南来解决“jQuery 未定义”错误 什么是“jQuery 未定义”错误? 您可能会在浏览器中方便的控制台日志中发现此错误,该错误的描述性不强。“jQuery 未定义”到底是什么意思? 简而言之,此错误试图告诉您网站上的某些内容(例如插件)需要 jQuery 才能工作。由于某种原因,当浏览器尝试加载站点并请求特定的 jQuery 时,它不可用。 从理论上讲,此错误可能会导致任何想要访问该网站的人关闭您的网站。
由于大约78% 的网站使用 jQuery,这是一个非常常见 电话号码清单 的错误。 控制台日志中出现“jQuery 未定义”错误。 “jQuery未定义”错误的可能原因 这个错误可能会让你措手不及。您的网站昨天运行良好,发生了什么?这可能会让人头疼。 有一些事情可能会导致“jQuery 未定义”错误: 您的 WordPress 网站上安装的旧插件与您最近安装和激活的插件发生冲突。如果您最近安装或激活了新插件,或者您网站上的某些插件尚未更新,这可能是原因。 缓慢或性能不佳的托管环境可能会增加 jQuery 在调用时运行所需的时间。仔细检查您的服务器资源或错误日志以确认这一点。 您网站上的 JavaScript 在 jQuery 完全加载之前运行。或者,JavaScript 文件可能在页面加载时未正确加载。 您用于提高站点性能的 CDN 无法访问您的服务器。如果您没有使用CDN,则可以完全排除这种可能性。 您的 jQuery 版本存在错误或拼写错误。也许有人最近更改了核心文件或插件,这导致了冲突。 如何修复“jQuery 未定义”错误 现在我们将找到解决方案,但在修改代码之前,请记住对您的网站进行备份!即使是最有经验的开发人员也会时不时地犯错误,手头有一个备份可以防止您在解决问题时丢失任何重要的工作。 如果有机会,请像 Kinsta 客户一样,首先修复暂存或开发站点上的错误,然后提交修复并将更改发布到实时站点。 一旦采取了这些必要的预防措施,就可以修复错误了。 修复此错误需要熟悉添加、删除和修改代码。别担心,您不需要从头开始编写代码。但如果您准备好访问站点的代码(无论是通过 SFTP还是托管环境),这将会有所帮助。
通过仪表板代码编辑器编辑代码并不理想。如果您手头还没有一个好的文本编辑器,现在是时候安装一个了。 您可以使用以下一些选项来解决此错误并使您的网站再次可访问。 方法 1:使用“网络”选项卡检查 jQuery 是否正在加载 查看浏览器开发人员工具的“网络”选项卡,看看 jQuery 是否正在加载。这是进行快速验证的最简单的地方。 另一种方法是搜索可能导致错误的多个插件和主题。检查您网站的代码并验证是否包含 jQuery。如果只上传一次会更好。 如果未包含 转至wp-includes文件夹找到此代码,然后文件。如果这不起作用,或者您发现 jQuery 库实际上已经包含在内,请继续使用以下方法。 该代码片段可以粘贴到任何 FTP 编辑器中,只要它位于 文件中即可。 您的代码片段将如何出现在 文件中。 方法 2:确保 jQuery 已加载 当jQuery存在但未加载时,您可能会遇到“jQuery 未定义”错误。通过查找脚本源并将 URL 粘贴到新的浏览器或选项卡中来验证它是否加载。 例如,如果<script src=您将其设置为: 您的文本片段在代码编辑器中应如下所示。 您应该搜索以查找要测试的 URL 的文本片段。 然后,复制该部分并将其粘到新窗口或选项卡中。如果 jQuery 文件加载并显示了全部内容,您可以将其从列表中勾选出来。 方法 3:包含 Google 托管的 jQuery 和本地后备 这是包含在 JavaScript 中的绝佳选择,因为在本地主机上运行 jQuery可以改善网站的整体体验。它将有助于避免来自 CDN 的任何其他 jQuery 加载问题。注释位于开头,您的代码片段应如下所示。
由于大约78% 的网站使用 jQuery,这是一个非常常见 电话号码清单 的错误。 控制台日志中出现“jQuery 未定义”错误。 “jQuery未定义”错误的可能原因 这个错误可能会让你措手不及。您的网站昨天运行良好,发生了什么?这可能会让人头疼。 有一些事情可能会导致“jQuery 未定义”错误: 您的 WordPress 网站上安装的旧插件与您最近安装和激活的插件发生冲突。如果您最近安装或激活了新插件,或者您网站上的某些插件尚未更新,这可能是原因。 缓慢或性能不佳的托管环境可能会增加 jQuery 在调用时运行所需的时间。仔细检查您的服务器资源或错误日志以确认这一点。 您网站上的 JavaScript 在 jQuery 完全加载之前运行。或者,JavaScript 文件可能在页面加载时未正确加载。 您用于提高站点性能的 CDN 无法访问您的服务器。如果您没有使用CDN,则可以完全排除这种可能性。 您的 jQuery 版本存在错误或拼写错误。也许有人最近更改了核心文件或插件,这导致了冲突。 如何修复“jQuery 未定义”错误 现在我们将找到解决方案,但在修改代码之前,请记住对您的网站进行备份!即使是最有经验的开发人员也会时不时地犯错误,手头有一个备份可以防止您在解决问题时丢失任何重要的工作。 如果有机会,请像 Kinsta 客户一样,首先修复暂存或开发站点上的错误,然后提交修复并将更改发布到实时站点。 一旦采取了这些必要的预防措施,就可以修复错误了。 修复此错误需要熟悉添加、删除和修改代码。别担心,您不需要从头开始编写代码。但如果您准备好访问站点的代码(无论是通过 SFTP还是托管环境),这将会有所帮助。
通过仪表板代码编辑器编辑代码并不理想。如果您手头还没有一个好的文本编辑器,现在是时候安装一个了。 您可以使用以下一些选项来解决此错误并使您的网站再次可访问。 方法 1:使用“网络”选项卡检查 jQuery 是否正在加载 查看浏览器开发人员工具的“网络”选项卡,看看 jQuery 是否正在加载。这是进行快速验证的最简单的地方。 另一种方法是搜索可能导致错误的多个插件和主题。检查您网站的代码并验证是否包含 jQuery。如果只上传一次会更好。 如果未包含 转至wp-includes文件夹找到此代码,然后文件。如果这不起作用,或者您发现 jQuery 库实际上已经包含在内,请继续使用以下方法。 该代码片段可以粘贴到任何 FTP 编辑器中,只要它位于 文件中即可。 您的代码片段将如何出现在 文件中。 方法 2:确保 jQuery 已加载 当jQuery存在但未加载时,您可能会遇到“jQuery 未定义”错误。通过查找脚本源并将 URL 粘贴到新的浏览器或选项卡中来验证它是否加载。 例如,如果<script src=您将其设置为: 您的文本片段在代码编辑器中应如下所示。 您应该搜索以查找要测试的 URL 的文本片段。 然后,复制该部分并将其粘到新窗口或选项卡中。如果 jQuery 文件加载并显示了全部内容,您可以将其从列表中勾选出来。 方法 3:包含 Google 托管的 jQuery 和本地后备 这是包含在 JavaScript 中的绝佳选择,因为在本地主机上运行 jQuery可以改善网站的整体体验。它将有助于避免来自 CDN 的任何其他 jQuery 加载问题。注释位于开头,您的代码片段应如下所示。