【技术】each(callback)

点击前:  点击后:

html部分:

<button>Change colors</button>
<span></span>
<div>内容一</div>
<div>内容二</div>
<div>内容三</div>
<div>内容四</div>
<div id="stop">内容五--Stop here</div>
<div>内容六</div>
<div>内容七</div>
<div>内容八</div>

 

js部分:

$(function() {
  $("button").click(function () {
    $("div").each(function (index, domEle) {
      // domEle == this
      $(domEle).css("backgroundColor", "yellow");
      if ($(this).is("#stop")) {
      $("span").text("Stopped at div index #" + index);
      return false;
      }
    });
  });
});

posted @ 2015-08-11 14:38  ybingbing_1213  Views(197)  Comments(0)    收藏  举报