lizhenlin

输出每个 li 元素的文本:

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

亲自试一试

定义和用法

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

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

语法

$(selector).each(function(index,element))
  • index - 选择器的 index 位置
  • element - 当前的元素(也可使用 "this" 选择器)

分类:

技术点:

相关文章:

  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2021-12-10
  • 2022-12-23
  • 2022-03-05
  • 2022-12-23
猜你喜欢
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2021-09-10
  • 2021-09-26
  • 2022-12-23
相关资源
相似解决方案