each
英 [i:t?]? ?美 [it?]??
adj.每;各自的
pron.每個;各自
jquery each()方法 語法
作用:each() 方法規(guī)定為每個匹配元素規(guī)定運行的函數(shù)。返回 false 可用于及早停止循環(huán)。
語法:$(selector).each(function(index,element))
參數(shù):
參數(shù) | 描述 |
function(index,element)? | 必需。為每個匹配元素規(guī)定運行的函數(shù)。 |
index? | 選擇器的 index 位置 |
element? | 當前的元素(也可使用 "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>輸出每個列表項的值</button> <ul> <li>Coffee</li> <li>Milk</li> <li>Soda</li> </ul> </body> </html>
點擊 "運行實例" 按鈕查看在線實例