2017-06-12 69 views
0

在Chrome中添加幻灯片后在NextGen Gallary插件中出现错误代码。 Sildeshow页面中的错误部分?我找不到此页面。 在页脚中附加jQuery i链接。与我的jQuery文件有冲突吗?在wordpress中使用NextGen Gallery插件运行幻灯片时出现JQuery错误

请参阅所附图片和代码screenshot of error

JQMIGRATE: Migrate is installed, version 1.4.1 
slideshow:212 Uncaught TypeError: jQuery(...).nggShowSlideshow is not a function 
    at HTMLDocument.<anonymous> (slideshow:212) 
    at i (jquery.js?ver=1.12.4:2) 
    at Object.fireWith [as resolveWith] (jquery.js?ver=1.12.4:2) 
    at Function.ready (jquery.js?ver=1.12.4:2) 
    at HTMLDocument.K (jquery.js?ver=1.12.4:2) 
(anonymous) @ slideshow:212 
i @ jquery.js?ver=1.12.4:2 
fireWith @ jquery.js?ver=1.12.4:2 
ready @ jquery.js?ver=1.12.4:2 
K @ jquery.js?ver=1.12.4:2 

<script type="text/javascript"> 
jQuery('#ngg-slideshow-8c3cff8f8dc2fd0d87b86cbcbb01a9eb-207510-image-list').hide().removeClass('ngg-slideshow-nojs'); 
jQuery(function($) { 
    jQuery('#ngg-slideshow-8c3cff8f8dc2fd0d87b86cbcbb01a9eb-207510').nggShowSlideshow({ 
     id: '8c3cff8f8dc2fd0d87b86cbcbb01a9eb', 
     fx: 'fade', 
     width: 1000, 
     height: 600, 
     domain: 'https://localhost/marc1/', 
     timeout: 10000  }); 

<script type="text/javascript"> 
    jQuery('#ngg-slideshow-8c3cff8f8dc2fd0d87b86cbcbb01a9eb-207510-image-list').hide().removeClass('ngg-slideshow-nojs'); 
    jQuery(function($) { 
     jQuery('#ngg-slideshow-8c3cff8f8dc2fd0d87b86cbcbb01a9eb-207510').nggShowSlideshow({ 
      id: '8c3cff8f8dc2fd0d87b86cbcbb01a9eb', 
      fx: 'fade', 
      width: 1000, 
      height: 600, 
      domain: 'https://localhost/marc1/', 
      timeout: 10000  }); 

回答

0

这种类型的错误往往会becaused由jQuery插件(脚本)的JQuery本身已经加载之前被运行。从您的屏幕截图看,您已经手动将脚本手动添加到您的页面模板中。

在WordPress中,JQuery脚本应始终由wp_enqueue_script钩子加载并使用JQuery依赖项进行设置。

wp_enqueue_script(string $handle, string $src = '', array $deps = array(), string|bool|null $ver = false, bool $in_footer = false) 

如:

function load_my_script_SO44497195(){ 
    wp_register_script( 
     'my_script', 
     get_template_directory_uri() . '/js/myscript.js', 
     array('jquery') 
    ); 
    wp_enqueue_script('my_script'); 
} 
add_action('wp_enqueue_scripts', 'load_my_script_SO44497195'); 

然而,如果你真的必须通过HTML手动加载你的脚本,你应该在

// A $(document).ready() block. 
$(document).ready(function() { 
    console.log("ready!"); 
}); 

包装这个代码,或者至少把你的脚本中页脚让JQuery有机会首先加载。但是,你真的应该只是排队脚本。

所有这些都是一种猜测,因为我只有截图才会出现。如果我们能够访问现场,那将会容易得多。

另外,在你给出的代码块中,你有相同的脚本加载两次,也没有结束脚本标记</script>,这似乎不仅是不必要的,而且可能会导致问题。首先将它排序两次,因为它可能是问题的根源。