内容 |
JQuery中each的使用举例: <html> <head> <title>Untitled</title> <script src="jquery.1.7.1.min.js"></script> </head> <body> <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> </body> <script> $("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; } }); }); </script> </html> |