admin管理员组文章数量:1426594
In file1.js inside a function I need to call a function which is actually included in file2.js
How can I do it?
Thank you
Later edit: This is what I want:
function back(){
if (step!=0){
dijit.byId('stackContainer').back();
}else{
//here I should call the save() function from file2.js
}
}
In file1.js inside a function I need to call a function which is actually included in file2.js
How can I do it?
Thank you
Later edit: This is what I want:
Share Improve this question edited Nov 3, 2009 at 19:47 Jason Berkan 8,9147 gold badges31 silver badges39 bronze badges asked Nov 2, 2009 at 13:23 sica07sica07 4,9868 gold badges37 silver badges54 bronze badges 0function back(){
if (step!=0){
dijit.byId('stackContainer').back();
}else{
//here I should call the save() function from file2.js
}
}
5 Answers
Reset to default 3If you have multiple js files, you simply include all the files in the html page that you are using to call them. since javascript is globalised once you include it, you can call methods from another js file from a particular js file as long as both js files are included in the page.
Include both the js files in the same document. Then you can call one function in a js file from the other one.
You need to include both of the javascript files in the same HTML page:
<script type="text/javascript" src="file2.js"></script>
<script type="text/javascript" src="file1.js"></script>
You simply need to be careful with the ordering of the javascript file includes. Make sure that the file containing the function you want to call is included in the document first. Once the function is defined, it can be used.
<script type="text/javascript" src="file2.js"></script>
<script type="text/javascript" src="file1.js"></script>
本文标签: javascriptHow to include a js function from an external file inside a jsfileStack Overflow
版权声明:本文标题:javascript - How to include a js function from an external file inside a js.file? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745483266a2660270.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论