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;
      }
    });
    寻找爱
  • 相关阅读:
    commonjs promise/A 规范
    Java之抽象类
    Java中多态的用法
    Java之方法的重写
    Java中static的用法
    java中this的用法
    Java概述
    二叉排序树的创建、插入、删除
    常用排序算法
    LeetCode小白菜笔记[2]:Reverse Integer
  • 原文地址:https://www.cnblogs.com/carolina/p/5486110.html
Copyright © 2011-2022 走看看