jQuery + WordPress:$未定义 [英] jQuery + WordPress: $ is not defined
问题描述
以下代码在jQuery中遇到了一些问题。
The following code is having some problem with the jQuery.
<script type="text/javascript">
$(window).load(function() {
..
});
</script>
如果我在文档头中包含jQuery,然后使用上面的代码,它将正常工作。
但是,如果我使用包含jQuery的Wordpress函数 wp_enqueue_script
,我得到以下错误: $未定义
。
我可以从页面源中看到jQuery已正确加载到标题中。
我该如何解决它?谢谢。
If I include jQuery in the document head and then use the above code, it will work fine.
However, if I use include jQuery using the Wordpress function wp_enqueue_script
, I get following error: $ is not defined
.
I can see from the page source that the jQuery is loaded properly in the header.
How can I fix it? Thanks.
推荐答案
hey:使用 jQuery
$ c> Q 而不是$使它工作。 Wordpress通常包含一个脚本,在末尾调用 jQuery.noConflict()
,并保留$ undefined。
hey: Use jQuery
with a capital Q
instead of $ to make it work. Wordpress usually includes a script which calls jQuery.noConflict()
at the end, leaving $ undefined.
Ok if有人不喜欢这个答案评论之前dowvote请:)
Okies if someone don't like this answer comment before downvote please :)
jQuery(function($) { //jQuery passed in as first param, so you can use $ inside
// use $
});
这篇关于jQuery + WordPress:$未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!