`

json 遍历

阅读更多
<title>Insert title here</title>
<script src="jquery/jquery-1.11.1.js"></script>
<script src="jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$(".flip").click(function() {
			$(".panel").slideUp("slow");
		});

		$("#add").click(function() {
			alert("a");
			window.location = "login.action";
		});

		var str = [ 'A', 'B', 'C', 'D' ];

		var js = [ {
			id : 01,
			name : "小白",
			old : 29,
			sex : "男"
		}, {
			id : 02,
			name : "小蓝",
			old : 29,
			sex : "男"
		}, {
			id : 03,
			name : "小雅",
			old : 29,
			sex : "男"
		} ];

		$("#s").click(function() {
			$.each(str, function(key, val) {
				//回调函数有两个参数,第一个是元素索引,第二个为当前值
				alert('_mozi数组中 ,索引 : ' + key + ' 对应的值为: ' + val);
			});
		});

		$("#j").click(function() {
			var jsonData = eval(js);
			
			$.each(jsonData,function(key, val){
				alert('_mozi数组中 ,索引 : ' + key + ' 对应的值为: ' + val['name']);
			});
		});
	});
</script>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics