ArticleDirectory
- Loading 1...
- Loading 4! To end!
- Document. Ready 1!
- Document. Ready 2!
During development, it is inevitable that a script is inserted in the middle of the html body. Many colleagues often encounter this or that problem. The problem is simple. Some scripts can be executed only after the file (DOM) is loaded, the script inserted in the body (except for jquery. delayed execution of scripts such as readyCode) Is executed in the document loading (from top to bottom). jquery solves the problem of loading scripts in the document. The ready function is very convenient after the file is loaded and executed.
This article mainly solves problems encountered by many colleagues and reminds them not to make similar mistakes.
Test source code:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <title> jquery ready function tester. </title> <br/> <MCE: script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" mce_src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </MCE: S Scripts> <br/> <MCE: Script Type = "text/JavaScript"> <! -- <Br/> function writeln (s) {$ ("body "). append ("<p>" + S + "</p> "). append ("<br/>") ;}< br/> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body> <br/> <MCE: Script Type = "text/JavaScript"> <! -- <Br/> writeln ("loading 1... "); <br/> // --> </MCE: SCRIPT> <br/> <MCE: Script Type =" text/JavaScript "> <! -- </P> <p> $ (document). Ready (function () {writeln ("document. Ready 1! ") ;}); <Br/> writeln (" loading 2... "); <br/> // --> </MCE: SCRIPT> <br/> <MCE: Script Type =" text/JavaScript "> <! -- <Br/> $ (document). Ready (function () {writeln ("document. Ready 2! ") ;}); <Br/> writeln (" loading 3... "); <br/> // --> </MCE: SCRIPT> <br/> <MCE: Script Type =" text/JavaScript "> <! -- <Br/> writeln ("loading 4! To end! "); <Br/> // --> </MCE: SCRIPT> <br/> </body> <br/> </ptml> <br/>
Test results:
Loading 1...
Loading 4! To end!
Document. Ready 1!
Document. Ready 2!