jQuery each() 方法
實例
輸出每個<li> 元素的文本:
$("button").click(function(){
$("li").each(function(){
alert($(this).text())
});
});
$("li").each(function(){
alert($(this).text())
});
});
嘗試一下»
定義和用法
each() 方法為每個匹配元素規定要運行的函數。
提示:返回false可用於及早停止循環。
語法
$(selector).each(function(index,element))
参数 | 描述 |
---|---|
function(index,element) | 必需。为每个匹配元素规定运行的函数。
|