This article illustrates the execution order of multiple $(document).ready() in the form of an example. From the example, it can be seen that the execution order of multiple $(document).ready() is not simply executed sequentially, and it also has a certain relationship with the nesting level. 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>KKKKKKKKKKKKKKKKKKKK<script type="text/javascript"> $(function(){ alert('6'); $(document).ready(function() { alert('7'); }); });</script></body></html>Run alert display order is: 1, 4, 6, 2, 5, 7, 3
Readers can test it themselves to deepen their understanding of the execution order of multiple $(document).ready().