admin管理员组文章数量:1410697
I have multiple external javascript files linked to my html page and want to call a function in one of them. Right now I'm doing onClick = "func()", but it's not calling the function. I'm trying to figure out the problem.....Do I need to specify which script the function is in? If so, how do I do that? Thanks.
Here is code:
<script type="text/javascript" src="file1.js"></script>
<script type="text/javascript" src="file2.js"></script>
...
<li id="tab"><span onClick = "get_code('tabOne')">Tab</span></li>
...
In file1.js:
function get_code(str)
{
alert(str);
}
I have multiple external javascript files linked to my html page and want to call a function in one of them. Right now I'm doing onClick = "func()", but it's not calling the function. I'm trying to figure out the problem.....Do I need to specify which script the function is in? If so, how do I do that? Thanks.
Here is code:
<script type="text/javascript" src="file1.js"></script>
<script type="text/javascript" src="file2.js"></script>
...
<li id="tab"><span onClick = "get_code('tabOne')">Tab</span></li>
...
In file1.js:
function get_code(str)
{
alert(str);
}
Share
Improve this question
edited Jun 30, 2011 at 20:17
demongolem
9,71636 gold badges97 silver badges105 bronze badges
asked Mar 18, 2011 at 22:52
rachrach
6916 gold badges16 silver badges20 bronze badges
1
- 1 Can you post the relevant JavaScript and HTML? – Ewan Heming Commented Mar 18, 2011 at 22:55
3 Answers
Reset to default 1By not working, do you mean that you do not get an alert box at all? or is the alert not displaying what you want? If it's not displaying what you want, it could be because your code alert(st);
is wrong, it should be alert(str);
.
Do onmouseover=""
or onclick=""
show the dialog? Javascript is case-sensitiv.
If you try to copy the file.js function and paste it in <HEAD>
section of HTML, does that work? Also, you should place <script type="text/javascript" src="file1.js"></script>
in the <HEAD>
section of your HTML. Check for any variable name clashes. Also, in the alert function, you are passing st
wherein it should be str
. Make sure your Javascript path is correct. Right now, javascript files should be in the same directory.
How about trying out
<li id="tab" onClick="get_code('tabOne');">Tab</li>
本文标签: htmlmultiple external javascript files how to call functionStack Overflow
版权声明:本文标题:html - multiple external javascript files- how to call function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745028267a2638336.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论