zoukankan      html  css  js  c++  java
  • jQuery: .each(function)

    Iterate over a jQuery object, executing a function for each matched element.

    .each(function)

    function

    type: Function(Integer index, Element element)

    a function to execute for each matched element

    When called it iterates over the DOM elements that are part of the jQuery object.Each time the callback runs, it is passed the current loop iteration,begginning from 0.

    the callback is fired in the context of the current DOM element, so the keyword this refers to the element.this == element

    example:

    <ul>

      <li>foo</li>

      <li>bar</li>

    </ul>

    $('li').each(function(index){

    console.log(index + ": " + $(this).text());

    })

    输出:

    0: foo

    1: bar

    you can stop the loop from within the callback function by returning false.

    $( "div" ).each(function( index, element ) {
      // element == this
      $( element ).css( "backgroundColor", "yellow" );
      if ( $( this ).is( "#stop" ) ) {
        $( "span" ).text( "Stopped at div index #" + index );
        return false;
      }
    });
    寻找爱
  • 相关阅读:
    【转】Delphi 关键字详解
    import datetime
    addlayer添加神经网络层
    xadmin使用富文本
    django安装xadmin
    django安装DjangoUeditor富文本
    django中admin一些方法
    Centos7.6安装python3.6.8
    django错误处理
    mysql 快速生成百万条测试数据
  • 原文地址:https://www.cnblogs.com/carolina/p/5486110.html
Copyright © 2011-2022 走看看