Home  >  Article  >  Web Front-end  >  Detailed explanation of basic usage examples of jquery's each loop

Detailed explanation of basic usage examples of jquery's each loop

伊谢尔伦
伊谢尔伦Original
2017-06-16 10:33:481710browse

Common loop statements in javascript are: whileloop do whileloop and forLoop . All three types of loop statements have their own advantages.

1. While loop

Format As follows:

## while (condition){

Code that needs to be executed

}

document.write("Here is the input of 1-50 printed by while:");

var i = 1;

while(i25cad3546873fef9dd6cd121c0cd60f82--->4-->3

When does the for loop end: When the logical judgment is false (false), This terminates the cycle.

Example: Print from 1 to 100;

for(var i=1;i<=100;i++){

document.wirter(" "+i)

}

##The difference between the three is demonstrated by a small case:

do{

##document.write("Will this be entered into the page?");

}while(1==2);

for(var i=1;i==2;i++){

document .write("Will for be entered into the page here?");

}

while(i==2){

document.write("While will this be input to the page?");

}

Proved by actual practice: the content in the do while statement will be output directly.

Summary: The difference between for loop while loop do while loop is that: do while will execute the loop body once regardless of whether the logical conditions are met, while while and for But it won't.

Attached jquery each() loop-try it yourself

      <html>
    <head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $("button").click(function(){
        $("li").each(function(){
          alert($(this).text())
        });
      });
    });
    </script>
    </head>
    <body>
    <button>输出每个列表项的值</button>
    <ul>
    <li>Coffee</li>
    <li>Milk</li>
    <li>Soda</li>
    </ul>
    </body>
    </html>



The above is the detailed content of Detailed explanation of basic usage examples of jquery's each loop. For more information, please follow other related articles on the PHP Chinese website!

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