JavaScript WordPress未捕获的typeerror $不是函数 [英] JavaScript WordPress uncaught typeerror $ is not a function

查看:62
本文介绍了JavaScript WordPress未捕获的typeerror $不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(document).ready(function(){
   $(".showhide").click(function(){
      $("nav").slideToggle("slow");
   });
});

我不是JavaScript程序员.我收到此错误:Uncaught TypeError $ is not a function

I'm not a JavaScript programmer. I'm getting this error: Uncaught TypeError $ is not a function

由于某种原因,我的导航无法正常工作. 有人告诉我将其放在JavaScript中,但出现错误.

For some reason my navigation is not working. Someone told me to put this in JavaScript but I'm getting the error.

发现了这个:jQuery(document);,但是不知道如何使用.

Found this: jQuery(document); but don't know how to use this.

推荐答案

这是您应该特别在WordPress上执行的方法(因为Wordpress通常使用jQuery而不是$)

This is how you should do it specially on WordPress (since Wordpress is usually using jQuery instead of $)

(function($){
  $(document).ready(function(){
   $(".showhide").click(function(){
      $("nav").slideToggle("slow");
   });
  });

})(jQuery);

参考此处

或者如果您不喜欢上面的答案,则可以在$(document).ready函数之前添加var $ = jQuery;

or if you don't like the answer above, you can add var $ = jQuery; before the $(document).ready function

这篇关于JavaScript WordPress未捕获的typeerror $不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆