简体   繁体   English

如果我使用 jQuery(document).ready(function(){ ... my code}) = undifined function

[英]If i use jQuery(document).ready(function(){ … my code}) = undifined function

I'm trying to use owl carousel in a wordpress ACF custom block.我正在尝试在 wordpress ACF 自定义块中使用 owl carousel。

owl carousel works if I don't put jQuery(document).ready in my script.如果我不将jQuery(document).ready放在我的脚本中,owl carousel 就可以工作。 But if I have jQuery(document).ready , the console tells me "jQuery (...). OwlCarousel is not a function".但是如果我有jQuery(document).ready ,控制台会告诉我“jQuery (...). OwlCarousel 不是一个函数”。

Then i don't know if there is link beetwen both but i have thumbnail gallery to click for launch slider on specific image and that code :然后我不知道两者是否都有链接,但我有缩略图库可以点击特定图像和代码上的启动滑块:

jQuery('.single_image_gallery').click(function(){
    mySlide = parseInt(jQuery(this).attr('data-slide'));
    jQuery(mySlider).trigger("to.owl.carousel", [mySlide, 1,true])  
})

not working at all.根本不工作。

i know there is problem with jQuery migrate for wp 5.5 but I tried with the plugin "Enable jQuery Migrate Helper" and the result is the same....我知道 jQuery migrate for wp 5.5 存在问题,但我尝试使用插件“Enable jQuery Migrate Helper”,结果是一样的......

Try doing this.. Sometimes plugins can interfere with jQuery尝试这样做.. 有时插件会干扰 jQuery

jQuery(function($) {
// then use it like this
 $('.single_image_gallery').click(function(){
   mySlide = parseInt($(this).attr('data-slide'));
   $(mySlider).trigger("to.owl.carousel", [mySlide, 1,true])  
 });  
});

This way you import $ locally and it should prevent it from interfering with other global scripts or plugins这样你就可以在本地导入 $ ,它应该防止它干扰其他全局脚本或插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM