jQuery中each()的用法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/farxix/article/details/80564121

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

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

//输出每个 li 元素的文本:
$("button").click(function(){
  $("li").each(function(){
    alert($(this).text())
  });
});

语法:

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

详解:

function(index,element)
必需。为每个匹配元素规定运行的函数。

index - 选择器的 index 位置
element - 当前的元素(也可使用 "this" 选择器)

猜你喜欢

转载自blog.csdn.net/farxix/article/details/80564121