首页 > Web开发 > 详细

Jquery中的$().each() 方法

时间:2015-11-06 11:14:17      阅读:207      评论:0      收藏:0      [点我收藏+]

先举例子,

输出每个 li 元素的文本:

技术分享
 1 <html>
 2 <head>
 3 <script type="text/javascript" src="/jquery/jquery.js"></script>
 4 </head>
 5 <body>
 6 <button>输出每个列表项的值</button>
 7 <ul>
 8 <li>Coffee</li>
 9 <li>Milk</li>
10 <li>Soda</li>
11 </ul>
12 </body>
13 <script type="text/javascript">
14 $(document).ready(function(){
15   $("button").click(function(){
16     $("li").each(function(){
17       alert($(this).text())
18     });
19   });
20 });
21 </script>
22 
23 </html>
View Code

语法:
  $(selector).each(function(index,element))

说明: function(index,element)

其中function函数为是必需的,它为每一个匹配元素规定了运行的函数

index为选择器的位置,element指向当前的元素(也可以使用“this”选择器)。

 

Jquery中的$().each() 方法

原文:http://www.cnblogs.com/heyijing/p/4941782.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!