each
英 [i:t?]? ?美 [it?]??
adj.每;各自的
pron.每個(gè);各自
jquery each()方法 語(yǔ)法
作用:each() 方法規(guī)定為每個(gè)匹配元素規(guī)定運(yùn)行的函數(shù)。返回 false 可用于及早停止循環(huán)。
語(yǔ)法:$(selector).each(function(index,element))
參數(shù):
參數(shù) | 描述 |
function(index,element)? | 必需。為每個(gè)匹配元素規(guī)定運(yùn)行的函數(shù)。 |
index? | 選擇器的 index 位置 |
element? | 當(dāng)前的元素(也可使用 "this" 選擇器) |
jquery each()方法 示例
<html> <head> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("li").each(function(){ alert($(this).text()) }); }); }); </script> </head> <body> <button>輸出每個(gè)列表項(xiàng)的值</button> <ul> <li>Coffee</li> <li>Milk</li> <li>Soda</li> </ul> </body> </html>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例