2015-10-30 78 views
0

這是我enqueue的WordPress的JavaScript,但我有這個錯誤。 「未捕獲的ReferenceError:myfunction未定義」。WordPress的:Uncaught ReferenceError:我的功能沒有定義

(function($) { 
    function myfunction(bf) { 
     if(bf.checked) 
      var text1 = document.getElementById("shipping_first_name").value; 
     else 
      text1=''; 
     document.getElementById("billing_first_name").value = text1; 
     }; 
})(jQuery); 

此外我也試過這個代碼。

(function($) { 
    jQuery(document).ready(function($) { 

     function myFunction(bf) { 
      if(bf.checked) 
       var text1 = document.getElementById("shipping_first_name").value; 
      else 
       text1=''; 

      document.getElementById("billing_first_name").value = text1; 
      } 
    }); 
})(jQuery); 

排隊:

function my_scripts_method() { 
    wp_enqueue_script(
     'custom-script', 
     get_template_directory_uri() . '/js/shipping.js', 
     array('jquery'), 
     false, 
     '1.0', 
     true 
    ); 
} 

add_action('wp_enqueue_scripts', 'my_scripts_method'); 
+2

的方法定義內clouser從clouser本身只訪問。 (函數(){ /*** * /} ) –

回答

3

封閉內部限定的方法是僅蓋子本身內部接近。

  (function(){ 
       /* This is called closure 
       All code here is solely on clouser 
       */ 
      }()) 

要訪問的方法,你可以改變封閉如下

  (function(){ 
       window.myfunction = function(bf){ 
        /*...*/ 
       } 
      }()) 
+0

我真的不明白,何談noconflict(})(jQuery的);) –

+2

我猜你的意思是封閉,不closour :) – vard

+0

是,非常抱歉 –

相關問題