Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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
jQuery on load函数不使用新版本Uncaught TypeError:$不是函数_Jquery_Wordpress - Fatal编程技术网

jQuery on load函数不使用新版本Uncaught TypeError:$不是函数

jQuery on load函数不使用新版本Uncaught TypeError:$不是函数,jquery,wordpress,Jquery,Wordpress,我以前在WordPress/WooCommerce设置中遇到jQuery冲突 为了解决这个问题,我返回到WordPress中包含的jQuery // Remove themes old version of jQuery and load a compatible version add_action('wp_enqueue_scripts', 'update_jquery_for_cherry_framework', 11); function update_jquery_for_cherr

我以前在WordPress/WooCommerce设置中遇到jQuery冲突

为了解决这个问题,我返回到WordPress中包含的jQuery

// Remove themes old version of jQuery and load a compatible version
add_action('wp_enqueue_scripts', 'update_jquery_for_cherry_framework', 11);

function update_jquery_for_cherry_framework() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', '/wp-includes/js/jquery/jquery.js', false, false, true);
   wp_enqueue_script('jquery');
}
当我进行此更改时,我的所有jQuery函数都开始失败,chrome控制台开始输出错误:

未捕获类型错误:$不是函数

为了解决这个问题,我必须像这样封装我的函数

jQuery(document).ready(function($){
// script
});
这修复了jQuery冲突,它们都重新开始工作。 我的问题是我只能用
(document).ready
实例来解决这个问题

我的一个jQuery函数必须在document ready函数之后触发,也就是说,
window.onload
函数之后触发

下面是有问题的脚本:

<script>
$(window).load(function() {
  $(".parallax-slider").css({
    'margin-left': $(".parallax-bg").css("marginLeft")
  });
  $(".parallax-slider").fadeIn(2500 , function(){
    $(this).css("display","normal");
  });
  $(window).resize(function(){
    $(".parallax-slider").css({
    'margin-left': $(".parallax-bg").css("marginLeft")
    });
  });
});
</script>
但是我仍然得到错误
uncaughttypeerror:$不是
$(窗口)的函数

我还尝试了其他方法,比如添加
}(jQuery)在我的代码末尾

正如我所说,jQuery(document)的一切都很好。ready(function($){
)。当我需要使用
$(window)。load(function(){
jQuery(window)。load(function($){
)或其他任何东西时,我如何让脚本在实例中工作

编辑:

感谢@abourne的解决方案

<script>
jQuery(window).load(function(){
  jQuery(".parallax-slider").css({
    'margin-left': jQuery(".parallax-bg").css("marginLeft")
  });
  jQuery(".parallax-slider").fadeIn(2500 , function(){
    jQuery(this).css("display","normal");
  });
jQuery(window).resize(function(){
       jQuery(".parallax-slider").css({
    'margin-left': jQuery(".parallax-bg").css("marginLeft")
  });
  });
});
</script>

jQuery(window).load(函数(){
jQuery(“.parallax slider”).css({
“左边距”:jQuery(“视差背景”).css(“左边距”)
});
jQuery(“.parallax slider”).fadeIn(2500,function(){
jQuery(this).css(“显示”、“正常”);
});
jQuery(窗口).resize(函数(){
jQuery(“.parallax slider”).css({
“左边距”:jQuery(“视差背景”).css(“左边距”)
});
});
});
基本上,我必须将
$
的实例更改为
jQuery
。重新加载,并且它正常工作,没有控制台错误

jQuery(window).load(){
    $(window).resize(function(){
       $(".parallax-slider").css({
         'margin-left': $(".parallax-bg").css("marginLeft")
       });
    });
  }); 
实际上非常接近您需要的。请尝试更换

 $(window).resize(function(){

同样的

 $(".parallax-slider").css({


我认为您应该通过提供wordpress版本差异、url或一些更有用的东西来完成您的问题:)你确定没有复制jquery include吗?我的脚本工作得很好。我只是在弄清楚如何封装我的新jquery以使用
window.onload
。所有其他jquery实例对
document.ready
都工作得很好。我检查了排队的
jquery.js
文件,并查看了它的状态s
jQuery v1.12.4
谢谢。我根据您的方法编辑了原始问题和整个解决方案。考虑到
文档。ready
使用了
$
很好,我正朝着各个方向努力使
加载
工作。谢谢您的解决方案!
 jQuery(window).resize(function(){
 $(".parallax-slider").css({
jQuery(".parallax-slider").css({