zoukankan      html  css  js  c++  java
  • jQuery 之 遍历

    1、jQuery对象.each(callback)

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>遍历</title>
      <script src="js/jquery.js">
      </script>
      <script type="text/javascript">
        $(function(){
          var wifes =$("#wife li");
          wifes.each(function(index,obj){
            //index:就是元素在集合中的索引
                    //obj:就是集合中的每一个元素对象
            //this:集合中的每一个元素对象
            alert(index+":"+$(obj).html());
          });
        });
      </script>
    </head>
    <body>
      <ul id="wife">
        <li>加藤惠</li>
        <li>斋藤飞鸟</li>
        <li>西野七濑</li>
        <li>石原里美</li>
        <li>亚丝娜</li>
      </ul>
    
    </body>
    </html>

    2、$.each(obj,callback)

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>遍历</title>
      <script src="js/jquery.js">
      </script>
      <script type="text/javascript">
        $(function(){
          var wifes =$("#wife li");
          //   //this:集合中的每一个元素对象
          $.each(wifes,function(index){
            alert(index+":"+$(this).html());
          });
        });
      </script>
    </head>
    <body>
      <ul id="wife">
        <li>加藤惠</li>
        <li>斋藤飞鸟</li>
        <li>西野七濑</li>
        <li>石原里美</li>
        <li>亚丝娜</li>
      </ul>
    
    </body>
    </html>

    3、for ...of

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>遍历</title>
      <script src="js/jquery.js">
      </script>
      <script type="text/javascript">
        $(function(){
          var wifes =$("#wife li");
          for (wife of wifes) {
            alert($(wife).html());
          }
        });
      </script>
    </head>
    <body>
      <ul id="wife">
        <li>加藤惠</li>
        <li>斋藤飞鸟</li>
        <li>西野七濑</li>
        <li>石原里美</li>
        <li>亚丝娜</li>
      </ul>
    
    </body>
    </html>
  • 相关阅读:
    Final TFS 2008 Feature List
    来看看微软对测试是什么要求
    淘宝设计流程
    Disable try catch
    jQuery validate API
    iPhone手机开发平台入门介绍和教程
    VSSpeedster Speed up your VS 2010
    Where are the SDK tools? Where is ildasm?
    效率高的删除语句truncate table [tablename]
    修改Hosts去除各站广告
  • 原文地址:https://www.cnblogs.com/zero-vic/p/13263164.html
Copyright © 2011-2022 走看看