• 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;
      }
    });
    寻找爱
  • 相关阅读:
    关于android4.3 Intel X86 Atom System Image的下载
    dp和px以及sp
    Android项目结构分析
    Performance Testing
    Modifying a Request or Response
    Log Sessions to Local Database
    The Web Sessions List
    Using QuickExec
    AutoResponder Reference
    Fiddler Session标志
  • 原文地址:https://www.cnblogs.com/carolina/p/5486110.html
Copyright © 2020-2023  润新知