jQuery 遍历 - each() 方法
定义和用法
each() 方法规定为每个匹配元素规定运行的函数。
提示:返回 false 可用于及早停止循环。
语法
$(selector).each(function(index,element))
| function(index,element) | 必需。为每个匹配元素规定运行的函数。
|
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("li").each(function(i,e){
alert($(e).text()+i)
});
});
});
</script>
</head>
<body>
<button>输出每个列表项的值</button>
<ul>
<li>Coffee</li>
<li>Milk</li>
<li>Soda</li>
</ul>
</body>
</html> 相关推荐
大象从不倒下 2020-07-31
AlisaClass 2020-07-19
淡风wisdon大大 2020-06-06
SoShellon 2013-06-01
chenshuixian 2013-06-01
羽化大刀Chrome 2013-05-31
LutosX 2013-07-29
ligaoyuan00 2013-03-31
swift 2013-03-26
quanhaoH 2013-06-17
周公周金桥 2020-09-06
zjuwangleicn 2020-09-04
hellowzm 2020-08-18
尚衍亮 2020-06-12
黎豆子 2020-05-07
hilary0 2020-05-04
zhanghao 2020-04-21
MaureenChen 2020-04-21