简体   繁体   English

无法使jQuery .getScript可以用于调用函数?

[英]Can't get the jQuery .getScript to work for calling a function?

From the file file2.js I'm trying to call a function foo() that is defined in file1.js. 我正在尝试从文件file2.js中调用在file1.js中定义的函数foo()。 In file1.js the function looks like: 在file1.js中,该函数如下所示:

function foo(){
   alert("Here");       
}

In file2.js I try calling this function like this: 在file2.js中,我尝试这样调用此函数:

$.getscript('file1.js', function(){
   foo();
}); 

However, this function is not being called. 但是,没有调用此函数。 Any ideas to what I need to do to fix this? 我需要采取什么措施来解决此问题? Thanks for any response. 感谢您的任何回复。

You have a typo in getScript (note the case): 您在getScript有一个错字(请注意大小写):

$.getScript('file1.js', function() {...});

Per jQuery getScript docs: https://api.jquery.com/jquery.getscript/ 每个jQuery getScript文档: https ://api.jquery.com/jquery.getscript/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM