Wordpress: Uncaught ReferenceError: myfunction is not defined
Wordpress: Uncaught ReferenceError: myfunction is not defined
这是 javascript 我在 wordpress 中排队,但出现此错误。 "Uncaught ReferenceError: myfunction is not defined ".
(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' );
在闭包内部定义的方法只能在闭包本身内部访问。
(function(){
/* This is called closure
All code here is solely on clouser
*/
}())
要访问该方法,您可以按如下方式更改闭包
(function(){
window.myfunction = function(bf){
/*...*/
}
}())
这是 javascript 我在 wordpress 中排队,但出现此错误。 "Uncaught ReferenceError: myfunction is not defined ".
(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' );
在闭包内部定义的方法只能在闭包本身内部访问。
(function(){
/* This is called closure
All code here is solely on clouser
*/
}())
要访问该方法,您可以按如下方式更改闭包
(function(){
window.myfunction = function(bf){
/*...*/
}
}())