Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在wordpress子主题中使用$代替jQuery_Jquery_Wordpress_Themes - Fatal编程技术网

在wordpress子主题中使用$代替jQuery

在wordpress子主题中使用$代替jQuery,jquery,wordpress,themes,Jquery,Wordpress,Themes,$I正在构建一个wordpress(3.6版)网站,使用一个儿童主题,主题为213。 我的主题的header.php <body <?php body_class(); ?> onResize="resizeHandler();"> 为了使用$而不是“jQuery”,我尝试了在web上找到的解决方案。新的myChildTheme.js: jQuery(document).ready(function($) { var myStuff; function

$I正在构建一个wordpress(3.6版)网站,使用一个儿童主题,主题为213。 我的主题的header.php

<body <?php body_class(); ?> onResize="resizeHandler();">
为了使用$而不是“jQuery”,我尝试了在web上找到的解决方案。新的myChildTheme.js:

jQuery(document).ready(function($) {
    var myStuff;
    function resizeHandler() {
        myStuff = $(".stuff");
        console.log("resized, and here's stuff: "+ myStuff);
    }
});
但是我得到一个控制台引用错误,说resizeHandler没有定义

我已经以我认为正确的方式排队并注册了主题的脚本和样式

functions.php:

function myChildTheme_scripts_styles() {
    wp_enqueue_style( 'myChildTheme-fonts', myChildTheme_fonts_url(), array(), null );
}
add_action( 'wp_enqueue_scripts', 'myChildTheme_scripts_styles' );

function myChildTheme_scripts() {
    wp_enqueue_script('myChildTheme_functions', get_stylesheet_directory_uri().'/js/myChildTheme.js', array('jquery'), '', true);
    wp_enqueue_script('isotope_source', get_stylesheet_directory_uri().'/js/jquery.isotope.min.js', array('jquery'), '', true);
}
add_action( 'wp_enqueue_scripts', 'myChildTheme_scripts' );

有没有关于如何让$1投入工作的提示?谢谢。

您需要通过jQuery本身附加
resize
事件。试试这个:

<body <?php body_class(); ?>>

仅供参考,您的控制台将输出调整大小的
,以下是内容:[Object Object]
-这是正常的。

.ready(函数($){
通过将代码包装到
文档中,您可以使用
$
而不是
jQuery
。ready
处理程序正在降低它的可见性。处理程序之外的任何东西都看不到它。另外,我看不到您在任何地方尝试使用
$
。对不起,我忘了使用
$
的正确示例。I corr我现在就去。
<body <?php body_class(); ?>>