jQuery Uncaught TypeError $ 不是函数(仅适用于几页) [英] jQuery Uncaught TypeError $ is not a function (only working on few pages)

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

问题描述

我对 jQuery 很陌生,我正在尝试将切换导航脚本包含到我的 Joomla 模板中.我包含了最新版本的 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 冲突,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天全站免登陆