Execution sequence instance analysis for multiple $of document.ready of
- 2020-03-30 03:35:27
- OfStack
This paper illustrates the execution order of multiple $(document). The specific example code is as follows:
<html>
<head>
<script src="./jquery-1.9.0.min.js"></script>
<script type="text/javascript">
$(function(){
alert('1');
$(function(){
alert('2');
$(function(){
alert('3');
});
});
});
</script>
<body>
TTTTTTTTTTTT
<script type="text/javascript">
$(document).ready(function() {
alert('4');
$(function(){
alert('5');
});
});
</script>
KKKKKKKKKKKK
<script type="text/javascript">
$(function(){
alert('6');
$(document).ready(function() {
alert('7');
});
});
</script>
</body>
</html>
Run the alert in order: 1,4,6,2,5,7,3
You can test the experience yourself to gain an understanding of the order in which multiple $(document).ready() are executed.