JavaScript中的遍历

for 遍历

var anArray = ['one','two'];
for(var n = 0; n < anArray.length; n++)
{    
//具体代码
}

for(var p in anObject)遍历

var anObject = {one: 1, two: 2};
for(var p in anObject)
{    
//具体代码
}

Jquery遍历

$.each遍历

//数组遍历
var anArray = ['one','two'];
$.each(anArray, funtion(n, value)
{ 
 alert(n);  
 alert(value);  
}
)

//对象遍历
var anObject = {one: 1, two: 2};
$.each(anObjct, function(name,value)
{    
alert(name);  
alert(value);  
}
)
posted on 2016-07-20 16:13  yxtic  阅读(541)  评论(0编辑  收藏  举报