最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to include a js function from an external file inside a js.file? - Stack Overflow

programmeradmin1浏览0评论

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:

function back(){
if (step!=0){
dijit.byId('stackContainer').back();
}else{
//here I should call the save() function from file2.js
}
}

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 0
Add a ment  | 

5 Answers 5

Reset to default 3

If 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>
发布评论

评论列表(0)

  1. 暂无评论