Also bad trouble let them write a new method, because they all refer to this aa.js file, want to be in this side after Aa.js perform a function automatically put JQ library introduced, so think of the introduction of JS file method:
Copy Code code 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. The DC is the creation object, the UI. A is a property assignment, the GT is a getelementsbytagname shorthand.
This executes ui.getscript ("Js/jquery/jquery-1.4.2.min.js", function () {alert ("Load Succeeded")});
Results in IE and FF did eject the success of the load, but when I use JQ in HTML in IE how can not execute, constantly refresh occasionally still can execute, put on the server and on the client static page also have a difference, but under Firefox no problem ...
So the thought is that the JQ file is loaded in parallel with the HTML load, and the HTML file is executed before the JQ load succeeds, and then the HTML is added at the end of the body
Copy Code code as follows:
<script>
Alert ("Pre-HTML Execution")
</script>
The execution discovery is really the first to eject the HMTL before the execution, and then eject the load successfully. The same is true of Firefox. When uploading to the server, it feels like Firefox pops up at the same time ...
Then began to understand how to set up to ensure that the JQ file after loading to execute the HTML body, how to add <script type= "Text/javascript" src= "Js/jquery.js" > </script> the introduction of the file.
Think always thought before browsing a page is he used a loading file to introduce a lot of JS files, in the HTML can use these introduced file functions, search to find this JS file content:
Copy Code code as follows:
var Collapsar = {
Version: ' 0.0.1 ',
Require:function (LibraryName) {
Inserting via DOM fails in Safari 2.0, so brute force approach
document.write (' <script type= "text/javascript" src= "' +libraryname+ '" ></script> ');
},
Load:function () {
if ((typeof prototype== ' undefined ') | |
(typeof Element = = ' undefined ') | |
(typeof element.methods== ' undefined ') | |
Parsefloat (Prototype.Version.split (".") [0] + "." +
Prototype.Version.split (".") [1]) < 1.5)
Throw ("The Prototype JavaScript framework 1.5.0+ is required");
$A (document.getElementsByTagName ("script")). FindAll (function (s) {
Return (s.src && s.src.match (/loader\.js). *)?$/))
}). Each (function (s) {
var path = s.src.replace (/loader\.js (\?). *)?$/,'');
var includes = S.src.match (/\?) *load= ([a-z,]*)/);
(Includes includes[1]: ""). Split (', '). each (
function (include) {
Collapsar.require (path+include+ '. js ')});
});
}
}
Collapsar.load ();
The call is <script type= "Text/javascript" src= "Js/loder.js?load=jquery,...,..." ></script> the files following the equals sign are introduced. In fact, this sentence is in the key role of document.write (' <script type= ' text/javascript "src=" ' +libraryname+ ' "></script> ');
I just saw some doubts. Write method is not like adding content in the document, the content should appear in the body tag Ah, the experiment found that if the string does appear in the document, when the script link and other tags appear in the head; That in the head to add a reference to the JS file and directly in the head of the same load them before the execution of the contents of the body .... What's the difference between him loading and adding script?
Experiment: Add in Aa.js:
Ui.getsc= (function () {
document.write (' <script type= "Text/javascript" src= "Js/jquery/jquery-1.4.2.min.js" ></script> ");
})()
Let him automate, in the body of the first line to introduce the JQ method, the experiment did succeed, in IE and in the FF as can be executed;
Sometimes continue to experiment ....... .......