为了账号安全,请及时绑定邮箱和手机立即绑定

未捕获的类型错误:$ 不是 (index):2 处的函数

未捕获的类型错误:$ 不是 (index):2 处的函数

PHP
元芳怎么了 2023-10-15 10:46:09
我在我的 WordPress 网站上遇到了这个错误“Uncaught TypeError: $ is not a function at (index):2”我找到了这个解决方案来添加var $ = jQuery.noConflict();之前$( document ).ready(function(){但是,我在网站的主题文件夹中找不到“$( document ).ready(function(){”代码来修复它。这是通过 Chrome 浏览器的检查、源窗口获得的确切代码<html class="no-js" itemscope itemtype="https://schema.org/WebPage"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /><link rel="alternate" hreflang="en" href="https://ccsi.global/"/><link rel="shortcut icon" href="https://ccsi.global/wp-content/uploads/2018/05/imageedit_89_3942571748.png" type="image/x-icon" /><link type="text/css" media="all" href="https://ccsi.global/wp-content/cache/autoptimize/css/autoptimize_9668264b3a77ccf7dc30b539d4038dbc.css" rel="stylesheet" /><title>Comcapint &#8211; Home &#8211; Compliance and Capacity Skills International</title><link rel='dns-prefetch' href='//fonts.googleapis.com' /><link rel='dns-prefetch' href='//s.w.org' /><link rel="alternate" type="application/rss+xml" title="Comcapint &raquo; Feed" href="https://ccsi.global/feed/" /><link rel="alternate" type="application/rss+xml" title="Comcapint &raquo; Comments Feed" href="https://ccsi.global/comments/feed/" /> <script type="text/javascript">window._wpemojiSettings = {"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/13.0.0\/72x72\/","ext":".png","svgUrl":"https:\/\/s.w.org\/images\/core\/emoji\/13.0.0\/svg\/","svgExt":".svg","source":{"concatemoji":"https:\/\/ccsi.global\/wp-includes\/js\/wp-emoji-release.min.js?ver=5.5"}};$(".nav-tabs a").click(function(){  $(this).tab('show');});$('.nav-tabs a').on('shown.bs.tab', function(event){  var x = $(event.target).text();         // active tab  var y = $(event.relatedTarget).text();  // previous tab  $(".act span").text(x);  $(".prev span").text(y);});});
查看完整描述

1 回答

?
一只甜甜圈

TA贡献1836条经验 获得超5个赞

大多数 WordPress 模板已经调用 noConflict()


当您想$在代码中使用时,最好使用 IIFE 包装器


(function($){

   // can use $ here

   $(document).ready....


})(jQuery);

jQuery还要确保您在加载库之前没有尝试使用。使用wp_enqueue_script()将解决这个问题


查看完整回答
反对 回复 2023-10-15
  • 1 回答
  • 0 关注
  • 70 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信