admin管理员组文章数量:1356515
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
4 Answers
Reset to default 3you 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
}
本文标签: javascriptnewbie question connect two functions int two filesStack Overflow
版权声明:本文标题:javascript - newbie question: connect two functions int two files - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744032376a2579150.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论