发表于 2012-09-28 09:43:46 by 月小升
each(fn)
说明:将函数作用于所有匹配的对象上
参数:fn (Function): 需要执行的函数
each 对于制作批量图片特效非常有用
<html>
<head>
<script type="text/javascript" src="jquery-1.8.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#test").click(function(){
//表示对每一个这个元素,执行这样的行为
$("img").each(function(){
this.src= "http://img.baidu.com/img/image/ilogob.gif";
});
$("div").each(function(){
this.innerHTML = "b";
});
});
});
</script>
</head>
<body>
<img src="http://news.baidu.com/resource/img/logo_news_137_46.png"/><br>
<img src="http://news.baidu.com/resource/img/logo_news_137_46.png"/>
<div >a</div>
<div >a</div>
<a href="#" id="test">jQuery</a>
</body>
</html> |
<html>
<head>
<script type="text/javascript" src="jquery-1.8.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#test").click(function(){
//表示对每一个这个元素,执行这样的行为
$("img").each(function(){
this.src= "http://img.baidu.com/img/image/ilogob.gif";
});
$("div").each(function(){
this.innerHTML = "b";
});
});
});
</script>
</head>
<body>
<img src="http://news.baidu.com/resource/img/logo_news_137_46.png"/><br>
<img src="http://news.baidu.com/resource/img/logo_news_137_46.png"/>
<div >a</div>
<div >a</div>
<a href="#" id="test">jQuery</a>
</body>
</html>
This entry was posted in
WEB前端 and tagged
jQuery. Bookmark the
permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:
月小升博客 –
https://java-er.com/blog/jquery-each/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力.