小白教程
所有教程
关于
Search
108.162.216.107
108.162.216.107
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Traversing each”的源代码
本页内容
上一节:
Traversing_contents
下一节:
Traversing_eq
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:each()}}[[Category:jquery ref traversing|5]] = jQuery each() 方法 = [[jquery ref traversing|jQuery 遍历方法]] 输出每个 <li> 元素的文本: <sample title="" desc="" lang="html" hererun="1"> $("button").click(function(){ $("li").each(function(){ alert($(this).text()) }); }); </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("li").each(function(){ alert($(this).text()) }); }); }); </script> </head> <body> <button>输出每个列表项的值</button> <ul> <li>Coffee</li> <li>Milk</li> <li>Soda</li> </ul> </body> </html> </run> == 定义和用法 == each() 方法为每个匹配元素规定要运行的函数。 '''提示:'''返回 false 可用于及早停止循环。 == 语法 == <pre> $(selector).each(function(index,element))</pre> {| class="table table-striped table-hover" !width="50%"| 参数 !width="50%"| 描述 |- | function(index,element) | 必需。为每个匹配元素规定运行的函数。 * index - 选择器的 index 位置。 * element - 当前的元素(也可使用 "this" 选择器)。 |} [[jquery ref traversing|jQuery 遍历方法]]
返回至“
Traversing each
”。
上一节:
Traversing_contents
下一节:
Traversing_eq