This article illustrates the execution order of multiple $(document).ready() in the form of examples. It can be seen from the examples that the execution order of multiple $(document).ready() is not a simple sequential execution. It is related to Nesting levels also have a certain relationship. 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 alert and the display order is: 1, 4, 6, 2, 5, 7, 3
Readers can test and experience it themselves to deepen their understanding of the execution sequence of multiple $(document).ready().