Introduce another JS file into one JS File

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.