中国最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2

Jquery手册

jQuery 杂项 each() 方法

阅读 (1878)

jQuery 杂项 each() 方法

jQuery 杂项方法 jQuery 杂项方法

实例

输出每个 <li> 元素的文本:

$("button").click(function(){
$("li").each(function(){
alert($(this).text())
});
});

尝试一下 »

定义和用法

each() 方法为每个匹配元素规定要运行的函数。

提示:返回 false 可用于及早停止循环。


语法

$(selector).each(function(index,element))

参数 描述
function(index,element) 必需。为每个匹配元素规定运行的函数。
  • index - 选择器的 index 位置。
  • element - 当前的元素(也可使用 "this" 选择器)。


jQuery 杂项方法 jQuery 杂项方法

关闭
程序员人生