jQuery each

  1. <ul id='a'>  
  2.   <li>aa</li>  
  3.   <li>dd</li>  
  4.   <li>dda</li>  
  5. </ul>  
  6. $("ul li ").each(function(){  
  7.     //alert($(this).text());  
  8. })  
  9. <button>Change colors</button>  
  10. <span></span>   
  11. <div></div>   
  12. <div></div>  
  13. <div></div>   
  14. <div></div>  
  15. <div id="stop">Stop here</div>   
  16. <div></div>  
  17. <div></div>  
  18. <div></div>  
  19. $("button").click(function () {   
  20.     $("div").each(function (index, domEle) {   
  21.       // domEle == this   
  22.           alert(index);  
  23.       $(domEle).css("backgroundColor""yellow");    
  24.       if ($(this).is("#stop")) {   
  25.           $("span").text("Stopped at div index #" + index);   
  26.           return false;   
  27.       }   
  28.     });  
  29. }); 

posted on 2011-07-29 11:00  EveryMan  阅读(165)  评论(0)    收藏  举报

导航