jQuery脚本无法在Wordpress中加载($不是函数) [英] jQuery Script fails to load in Wordpress ($ is not a function)

查看:81
本文介绍了jQuery脚本无法在Wordpress中加载($不是函数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究伊恩·伦恩(Ian Lunn)的互动式地图嵌入到了wordpress中.

I've been working on a version of Ian Lunn's interactive map embeded into wordpress.

该脚本可以在独立页面上完美运行,但是当加载到wordpress中时,脚本不会执行任何操作.我尝试了各种解决方案-以不同的方式加载jQuery(在functions.php,内联,页眉和页脚中),降级到jQuery的早期版本,对函数命名并为其命名.什么都没有发生,firebug没有显示错误,什么也没有.

The script works perfectly on a standalone page, but when loaded into wordpress, the script does nothing. I've tried various solutions - loading the jQuery in different ways (in functions.php, inline, in the header and footer), downgrading to an earlier version of jQuery, namespacing the functions, you name it. Nothing happens, firebug shows no errors, nothing.

在此阶段,我完全不知所措,我们将不胜感激.

I'm at a complete loss at this stage, any help offered would be greatly appreciated.

此处的工作演示: http://www.ianlunn.co .uk/demos/bbc-news-jquery-map/ Github来源: https://github.com/IanLunn/BBC-News-jQuery-Map

Working demo here: http://www.ianlunn.co.uk/demos/bbc-news-jquery-map/ Github source: https://github.com/IanLunn/BBC-News-jQuery-Map

//回答后更新

说明美元符号在WordPress中为Prototype库保留,这就是为什么它会错误地提示"$不是函数"-以下接受的答案指出了这一点,但仅在注释中指出,因此更新为明晰.例如:-

It transpires that the the dollar sign is reserved in WordPress for the Prototype library, which is why it errors out with '$ is not a function' - the accepted answer below points this out but only in the comments hence the update for clarity. For example:-

$().ready(function() {
   $("#select_me").show();
});

jQuery().ready(function() {
   jQuery("#select_me").show();
});

推荐答案

当我转到您的页面时,在Firebug控制台中看到两个错误.

I see two errors in the Firebug console when I go to your page.

第一个是:

XML can't be the whole program.
?>    map.js?ver3.2.1 (line 55)

第二个是:

document.getElementById("recaptcha-submit-btn-area") is null
/about/...ve-map/ (line 595)

然后我看到:

carouFredSel: No element selected.
jquery...r=1.4.2 (line 14)

您看不到此输出吗?

您的map.js的代码包装在PHP标记中,这就是问题所在.这是PHP代码以Javascript文件的形式传递给客户端.

Your map.js has code wrapped in PHP tags, that's the problem. It's PHP code being delivered to the client in a Javascript file.

这篇关于jQuery脚本无法在Wordpress中加载($不是函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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