Javascript file introduction implementation code _ javascript skills

Source: Internet
Author: User
Tags getscript
Project front-end files are separated from backend development. As long as backend development updates svn front-end js files and css files are updated, a js file such as AA is referenced previously. js. to reference the jquery library in the project, if the header of each file leads them to write the jq file again, it is unlikely or difficult for them to write a new method, because they all reference this AA. js file. after JavaScript code is executed, a function automatically introduces the jq library. Therefore, the method for introducing the js file is as follows:

The Code is as follows:


GetScript: function (s, call ){
Var el = UI. DC ('script ');
If (call ){
El. onload = el. onreadystatechange = call;
}
UI. A (el, 'type', 'text/javascript ');
UI. A (el, 'src', s );
UI. GT (document, 'head') [0]. appendChild (el );
}
/* UI. DC is the creation object, UI. A is the attribute value, and GT is the abbreviation of getElementsByTagName */


So execute UI. getScript ("js/jquery/jquery-1.4.2.min.js? 1.1.23 ", function () {alert (" loaded successfully ")});

The results show that the loading is successful in IE and ff, but when I use jq in HTML, I cannot execute it in IE. I can refresh it and execute it occasionally, there are also differences between static pages on the server and on the client, but there is no problem in Firefox .........

So I thought it was not because the jq file was loaded in parallel with the html file. Before jq was loaded successfully, the HTML file was executed, so I added it at the end of the html body.

The Code is as follows:


Script
Alert ("pre-html execution ")
Script


It is found that the execution is performed before hmtl is popped up, and then the loading is successful. This is also true under Firefox. When uploading to the server, I feel that the pop-up of Firefox will appear at the same time .....

So I started to wonder how to configure it to ensure that the jq file can be executed only after it is loaded.
Related Article

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.