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

javascript - newbie question: connect two functions int two files - Stack Overflow

programmeradmin2浏览0评论

This is a newbie question. I have two javascript and one html files. When I click on an image it goes to the first .js file and when it finnish to run all that code should go to the second .js file. But how can I connect the two functions that are in different files.

thanks

This is a newbie question. I have two javascript and one html files. When I click on an image it goes to the first .js file and when it finnish to run all that code should go to the second .js file. But how can I connect the two functions that are in different files.

thanks

Share Improve this question asked Jul 18, 2011 at 14:34 saomisaomi 8955 gold badges18 silver badges41 bronze badges 1
  • What do you mean by "it goes to the first .js file" and "should go to the second .js file"? Do you want to call the two functions with the same image passed as a parameter? – Jose Faeti Commented Jul 18, 2011 at 14:38
Add a ment  | 

4 Answers 4

Reset to default 3

you need just to define the 2 js files in the HTML header page :

<script type="text/javascript" src="one.js"></script> 
<script type="text/javascript" src="second.js"></script> 

It doesn't matter what files the functions are in, you can call the second function from the first one.

You should also consider why you are separateing your functions into seperate files - in general, they should all be in as few files as possible.

Like so:

In file1.js:

var foo = function(){
    bar();
};

In file2.js:

var bar = function(){
    alert('hello');
};

You will have something like this,

in the html file:

<input type="button" name="" onclick="random1();" />

in the first js file:

function random1(){
// your code here
random2();
}

in the second js file:

function random2(){
//your code here
}
发布评论

评论列表(0)

  1. 暂无评论