$(document).ready(function(){$('#id').each(function(){//do something代码});});
1
$(document).ready(function(){
2
$('#id).each(function(){
3
//do something 代码
4
});
5
});
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
1. 把代码包装在一个.each()方法中。
2.当使用id创建Jquery对象时,有两种可能的结果,
2.1 与id唯一匹配元素的Jquery对象。
2.2 没找到id将产生一个空对象, 而且空对象的.each()方法中的代码不执行。