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:

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>

本文标签: javascriptHow to include a js function from an external file inside a jsfileStack Overflow