jQuery Uncaught TypeError $不是函数(仅在少数页面上有效) [英] jQuery Uncaught TypeError $ is not a function (only working on few pages)

查看:98
本文介绍了jQuery Uncaught TypeError $不是函数(仅在少数页面上有效)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对jQuery很陌生,我正在尝试在我的Joomla模板中包含一个toggle-nav脚本. 我提供了最新版本的jQuery和用于存储函数的.js文件. 该脚本只能在几页上使用(例如,首页,商店),但不能在显示文章页面的页面上使用.

I am quite new to jQuery and I am trying to include a toggle-nav script to my Joomla template. I included the latest version of jQuery and my .js file where the function is stored in. The script works on few pages (e.g home, shop), but it does not work on pages where I display an article page.

我试图用简单的警报替换脚本.警报显示在所有页面上,因此脚本已正确包含. 也许jQuery并未正确包含,但那为什么要在家里或商店上使用它呢?.

I tried to replace the script with a simple alert. The alert shows up on all pages, so the script is included correctly. Maybe the jQuery isn't included correctly, but why should it work on the home or shop then..

我仅在脚本不起作用的情况下找到有关此问题的答案,但就我而言,它在我网站的某些页面上起作用.

I only found answers regarding this issue where the script does not work, but in my case it works on a few pages of my website.

这是我的功能:

$(document).ready(function() {

    $('.toggle-nav').click(function() {
      $('.navigation').toggleClass('show');
    });
});

非常感谢!

推荐答案

您的脚本可能与mootools发生冲突,这取决于您的joomla版本和脚本设置,这是常见的.请尝试以下操作:

Your script is probably conflicting with mootools which is common depending on your joomla version and script setup. Try the following:

// You might need this, usually it's autoloaded   
jQuery.noConflict();

// Replace $ with jQuery
jQuery(document).ready(function() {
    jQuery('.toggle-nav').click(function() {
      jQuery('.navigation').toggleClass('show');
    });
});

这篇关于jQuery Uncaught TypeError $不是函数(仅在少数页面上有效)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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