开发者

multiple external javascript files- how to call function

开发者 https://www.devze.com 2023-02-17 14:46 出处:网络
I have m开发者_Go百科ultiple 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 have m开发者_Go百科ultiple 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);
}


By 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>
0

精彩评论

暂无评论...
验证码 换一张
取 消