Include a JavaScript file in a JavaScript file

Possible Duplicate:
How to include a JavaScript file in another JavaScript file?

I want to include a JavaScript file in a JavaScript file. include('filename.js'); is not working

What is the right code?


function includeJS(incFile)
{
   document.write('<script type="text/javascript" src="'+ incFile+ '"></script>');
}

然后通过调用包含第二个JavaScript文件:

includeJS('filename.js');

Use:

<script language="javascript" src="first.js"></script> 
<script language="javascript" src="second.js"></script> 

You can access the variables from the first file in the second file.

There isn't any need to include one JavaScript file into another. JavaScript code is globalised. You can include both the files in the HTML/JSP page.


在第一个JavaScript函数中使用document.write

document.write('<scr'+'ipt type="text/javascript" src="filename.js" ></scr'+'ipt>'); 
链接地址: http://www.djcxy.com/p/7338.html

上一篇: 在JavaScript函数中导入JavaScript文件

下一篇: 在JavaScript文件中包含JavaScript文件