• 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>
  • 相关阅读:
    SAP HUM事务代码 HUMAT 之初探
    SAP HUM 锁住一个HU?
    SAP MM 标准采购组织的分配对于寄售采购订单收货的影响
    SAP MM已经转成PO的采购申请Item依旧可以被删除?
    SAP MM A工厂下的PR可以转成B工厂下的PO?
    SAP MM 明明已经扩展供应商到采购组织下,采购订单里还是报错?
    SAP HUM 事务代码HUMO为整托做Scrap
    2018-8-29-Roslyn-静态分析
    2018-2-13-win10-UWP-等级控件
    2018-2-13-win10-uwp-改变鼠标
  • 原文地址:https://www.cnblogs.com/zero-vic/p/13263164.html
Copyright © 2020-2023  润新知