2015-10-30 45 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

是,非常抱歉 –

相关问题