Home > Article > Web Front-end > Detailed explanation of js loading and execution order in html
jsLoading execution sequence in html
1. Loading sequence: introduce the order of appearance of the tag b97cb247ad0c0836255176e480ef452b,
# on the page ##JavascriptThe code is part of the HTML document, so the order in which Javascript is executed when the page is loaded is the order in which the introduction tags b97cb247ad0c0836255176e480ef452b appear, 25b61ca747de015cc2c310ffd8c02d9d//54f14c5664fc2489fa973c964bee6da2b294a02d2a53c7a839b9976353068ee2');
//]]>
2cacc6d41bbb37262a98f745aa00fbf0
4ec11beb6c39d0703d1751d203c17053//52d314faa0053e3aedecf4bcabd57199');
document.write('alert(2);')
document.write('alert("I am" + tmpStr);');
document .write('b294a02d2a53c7a839b9976353068ee2');
//]]>
2cacc6d41bbb37262a98f745aa00fbf0
4ec11beb6c39d0703d1751d203c17053// 3feaf32ad798e89650d3902613919e3d
2cacc6d41bbb37262a98f745aa00fbf0
In this way, the order of output values under IE and other browsers is consistent. : 1, 2, I am 1, 3
: Under IE, when using the Document.Write method to reference the js file, the js file will appear to have not been loaded. In the case of direct call, it is recommended to place the referenced JS file in a separate script block. To ensure that the referenced js file is fully loaded, continue to execute the subsequent Document.Write content5. JS function execution sequence with the same name
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <script type="text/javascript"> function aa() { alert('First aa') } </script> <title></title> </head> <body> <form id="form1" runat="server"> <br /> <input id="Button1" type="button" value="button" onclick="aa();"/> </form> </body> <script type="text/javascript"> function aa(s) { alert('Second aa'); } function aa(s) { alert('Last aa'); } </script> </html>
Click "botton" to execute the result: Last aa
After a function with the same name appears in js, after you call the js function in the web page, the last loaded function in the page will always be called.
The above is the detailed content of Detailed explanation of js loading and execution order in html. For more information, please follow other related articles on the PHP Chinese website!