jQuery each 用法

来源:互联网 发布:淘宝怎么退货手机 编辑:程序博客网 时间:2024/05/21 19:47

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;

 })

原创粉丝点击