我需要一个函数来检查jQuery中的函数是否存在,如果是,那么应该调用这个函数。如果我用一个简单的名字使用下面的代码,但是如果我想动态地检查一个函数是否存在,它不起作用。有没有人有想法?检查功能是否动态存在
function homeController() {
console.log('in the homecontroller');
}
$('div[class="view"]').each(function() {
$('#' + this.id).live('pageshow', function() {
var func = this.id + 'Controller';
if($.isFunction(func)) {
console.log('jquery exists');
}
});
});
你的意思是你想测试任意JavaScript函数是否在范围内?当然'func'在你的例子中只是一个字符串,而不是一个函数。 –