Home >Web Front-end >JS Tutorial >Analysis of execution sequence examples of multiple $(document).ready()_jquery

Analysis of execution sequence examples of multiple $(document).ready()_jquery

WBOY
WBOYOriginal
2016-05-16 16:41:021609browse

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().

Statement:
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