现在接触这些东西越来越少,很多东西似乎都忘记了。今天又重新翻起来看了遍,想在博客留下一个我学习过这个知识的痕迹。
现在要分享的这个知识点是jQuery中的$.each(index,el)方法、//index代表索引,el代表当前这个元素(this)。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>each方法</title>
<script type="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('li').each(function(index,el){
alert(index);
alert($(el).text());
})
})
</script>
</head>
<body>
<ul>
<li>yaya</li>
<li>jojo</li>
<li>lili</li>
</ul>
</body>
</html>
很多东西都一目了然了。这个index代表的是数组的索引,el代表的是当前元素this! 你学会了吗?