2017-06-12 70 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>,這似乎不僅是不必要的,而且可能會導致問題。首先將它排序兩次,因爲它可能是問題的根源。