It's not easy 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:
CopyCode 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", 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.Copy codeThe 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 began to wonder how to set it to ensure that the JQ file can be executed only after it is loaded, how to add <SCRIPT type = "text/JavaScript" src = "JS/jquery. JS "> </SCRIPT> ..
I thought that I used to browse a page and used a loading file to introduce many JS files. I can use these introduced file functions in HTML. I found the JS file content as follows:
Copy code Code: 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 primary des = S. SRC. Match (/\?. * Load = ([A-Z,] *)/);
(Des? Des [1]: ""). Split (','). Each (
Function (include ){
Collapsar. Require (path + include + '. js ')});
});
}
}
Collapsar. Load ();
<SCRIPT type = "text/JavaScript" src = "JS/Loder. js? Load = jquery ,...,... "> </SCRIPT> the file after the equal sign can be introduced. In fact, this sentence plays a key role in document. write ('<SCRIPT type = "text/JavaScript" src = "' + libraryname + '"> </SCRIPT> ');
I just saw some questions. Isn't the write method like adding content in the document? The content should appear in the body tag. The experiment found that if a string does appear in the document, if a tag such as script link appears in the head, add reference JS files to the head and load them directly in the head before executing the content in the body .... what is the difference between loading the script and adding it ........
Experiment: Add the following in AA. JS:
Ui. getsc = (function (){
Document. Write ('<SCRIPT type = "text/JavaScript" src = "JS/jquery/jquery-1.4.2.min.js"> </SCRIPT> ');
})()
Let him execute automatically. The JQ method is introduced in the first line of the body. The experiment is successful, and can be executed in the same way as in IE and ff;
You have time to continue the experiment ...................