The first JS file (the introduced JS file) is named one. js. The content is as follows:
Function alertinone () {
Alert ('in one ');
}
The second JS file named two. js. The content is as follows:
// Pay attention to this location
Document. Write ("<script language = 'javascript 'src = 'one. js'> </SCRIPT> ");
Function alertintwo () {
Alert ("in two ");
}
To call the HTML file, you only need to introduce two. js to introduce one. js.
<Script language = 'javascript 'src = "Two. js"> </SCRIPT>
<Script language = "JavaScript">
Alertinone ();
Alertintwo ();
</SCRIPT>
Application scenarios:
During normal development, we will accumulate some JS files, which do not need to be rewritten in most cases.
However, we will segment the functions of JS files as much as possible so that no useless information will be introduced during the introduction.CodeBut this causes the problem in the JSP file
To write a large number of such sentences
<Script language = 'javascript 'src = "Two. js" charset = "UTF-8"> </SCRIPT>
If you have 100 JSP files and use 10 JS files, it is troublesome to write 10 sentences for each JSP file.
Now, the introduction of JS files can solve this problem. Define a JS file to introduce some combinations, while the JSP file only needs to introduce one
You can use this JS file. JS Code is less than 100 lines * 99 lines
In addition, it is best to add charset to the introduced JS file, especially when your JS file contains non-English and numbers.
Sample Code download: http://www.blogjava.net/Files/dreamstone/importJs.rar