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;
      }
    });
    寻找爱
  • 相关阅读:
    细说Cookie(转)
    Custom Exception in ASP.NET Web API 2 with Custom HttpResponse Message
    内核中的定时器
    ibus拼音安装_ubuntu10.04
    linux模块
    zebra/quagga线程分析
    vim常用配置
    rar安装和使用
    zebra/quagga
    netsnmp编译动态库
  • 原文地址:https://www.cnblogs.com/carolina/p/5486110.html
Copyright © 2011-2022 走看看