wasw100's Blog
上一篇: 下一篇:
2010年05月24日

jquery,javascript遍历json数组例子

jquery,javascript遍历json数组例子如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jquery,javascript遍历json数组</title>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function(){
	var json = {users:[{id:1, name:"abc"},{id:2, name:"xyz"}]};
	//jquery遍历json数组
	$(json.users).each(function(index, entry){
		alert("jquery遍历 index:"+index+"  id:"+entry['id']+" name:"+entry['name']);
	});
	//javascript遍历json数组
	for(var i=0;i<json.users.length;i++){
		alert("javascript遍历 index:"+i+"  id:"+json.users[i].id+" name:"+json.users[i].name);
	}
});
</script>
</head>
</html>

–EOF–

返回顶部