将参数传递给作为参数传递给jQuery函数的函数 [英] pass argument to function passed as argument to jQuery function
问题描述
我试过每篇文章中的每一个变化,我都能找到。目前,我在一个js文件中有这个:
函数callThisThisPlease(testIt){
alert(testIt);
$(document).ready(function(){
$ .fn.pleaseCallTheOtherFunction('callThisPlease');
});
我在另一个中有这个:
<$ p $($)$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' 'works');
}
});
chrome控制台显示未捕获的TypeError:无法调用方法'apply'undefined
。
请帮忙。非常感谢!
如果方法在窗口
这意味着你的功能不是全球性的。使它成为一个全局函数。
另外,你可以去掉 .apply
。目前,您将'works'
作为这个
值。
window [functionName]('works');
Passing function name as a parameter to another function doesn't seem to work for me.
I've tried every variation from every article I can find. Currently, I have this in one js file:
function callThisPlease (testIt){
alert(testIt);
}
$(document).ready(function () {
$.fn.pleaseCallTheOtherFunction('callThisPlease');
});
I have this in another:
$(document).ready(function () {
$.fn.pleaseCallTheOtherFunction = function(functionName){
window[functionName].apply('works');
}
});
chrome console says Uncaught TypeError: Cannot call method 'apply' of undefined
.
Please help. Many thanks in advance!
If the method is undefined on window
, that means your function isn't global. Make it a global function.
Also, you can get rid of .apply
. Currently you're passing 'works'
as the this
value.
window[functionName]('works');
这篇关于将参数传递给作为参数传递给jQuery函数的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!