jQuery处理程序在Word Press中不工作

jQuery处理程序在Word Press中不工作,jquery,wordpress,Jquery,Wordpress,**编辑-我从头文件中删除了代码,并尝试从中执行说明 我在函数文件中添加了此代码 function shapeSpace_include_custom_jquery() { wp_deregister_script('jquery'); wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array(), null, true); } a

**编辑-我从头文件中删除了代码,并尝试从中执行说明

我在函数文件中添加了此代码

function shapeSpace_include_custom_jquery() {

    wp_deregister_script('jquery');
    wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array(), null, true);

}
add_action('wp_enqueue_scripts', 'shapeSpace_include_custom_jquery');

我在控制台中看到对CDN的GET请求成功。我还尝试将官方jquery站点的链接更改为

我有一个名为main.js的文件,其中包含以下代码-

(function ($) {
  console.log("working");

  $(".about-text").click(function () {
    alert("test")
  });

})(jQuery);
“工作”控制台日志显示,以便它知道已加载,但用于单击的jQuery处理程序没有。我也试过hover(),但不起作用,也试过-

$(".about-text).hide() 

这是我正在测试的div-

    <div class="about-text">
        <h2><?php the_title(); ?></h2>
        <h3><?php the_content(); ?></h3>
    </div>
(来自jquery.com网站的示例)并且它不起作用


我做错了什么?

在WordPress中,jQuery是以无冲突模式加载的,因此您不能像那样使用
$
,相反,您可以按如下方式使用jQuery,然后使用
$

jQuery(document).ready(function($) {  
    $( "#target" ).click(function() {   
       alert( "Handler for .click() called." ); 
    });   
}
或者你有另一个选择,比如


您是否有阻止
alert()
的内容拦截器?尝试使用
console.log
,也尝试使用
$(“body”)。在(“单击”,“关于文本”)上,function(){
尝试了,但仍然无法使用
jQuery(document).ready(function($){$(“#target”)。单击(function(){alert(“调用的.click()处理程序”)})
成功了!谢谢。你知道原因吗?在我的回答中添加;)
$( "#target" ).click(function() {
  alert( "Handler for .click() called." );
});
jQuery(document).ready(function($) {  
    $( "#target" ).click(function() {   
       alert( "Handler for .click() called." ); 
    });   
}
var j = jQuery.noConflict();
    j(document).ready(function() {  
        j( "#target" ).click(function() {   
           alert( "Handler for .click() called." ); 
        });   
    }