var obj={one:1,two:2,three:3};
$.each(obj,function(index,content){
alert(index);//索引 one two three
alert(content);//值 1 2 3
});
<p>1</p>
<p>2</p>
<p>3</p>
$(“p”).each(function(index){
alert(index);//索引 0 1 2
$(this).attr(“color”,”red”);
});
有时我们在遍历的时候,在符合一定条件时遍历就会停止,停止遍历的方法是
$(“p”).each(function(){
return false;
})