Home > Web Front-end > HTML Tutorial > Detailed explanation of js loading and execution order in html

Detailed explanation of js loading and execution order in html

高洛峰
Release: 2017-03-12 17:47:11
Original
1913 people have browsed it

jsLoading execution sequence in html

1. Loading sequence: introduce the order of appearance of the tag



In this way, the order of output values ​​under IE and other browsers is consistent. : 1, 2, I am 1, 3

Summary

: 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(&#39;First aa&#39;)
    }   
</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(&#39;Second aa&#39;);
    }
function aa(s) {
        alert(&#39;Last aa&#39;);
    }
</script>
</html>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template