通过JS、JQ,实现对json数据调取,并循环展示到页面

通过JS、JQ,实现对json数据调取,并循环展示到页面

 $(document).ready(function(){
	  data=$.ajax({url:"获取json链接地址",async:false});
	  data2 = data.responseText;
	  var data2 = JSON.parse(data2);
	  var data3 =data2.gamelists;
	  data3.forEach(function(e){
		$("#list1_info").append("<li><div class=\"game_img\"><a href="+decodeURIComponent(e.opengame_url)+"><img src=" + decodeURIComponent(e.icon_url) + "></a></div><div class=\"game_content\"><h1><a href=/" + decodeURIComponent(e.opengame_url) + ">" + e.zh_name + "</a></h1><div class=\"star_w\"><p style=\"width:40%\"></p></div><span>人气:" + e.clicks + "</span><div class=\"game_cwz\">" + e.brief + "</div></div><div class=\"game_button\"><a href=" + decodeURIComponent(e.opengame_url) + ">开始游戏</a></div></li>");
	  }) 
	});
//纯Jquery	
	function tab_nav(nav){
		$.getJSON("获取json链接地址", function (data) {
			$.each(data.gamelists,function (i, item){
				$("#list1_info").append("<li><div class=\"game_img\"><a href=" + decodeURIComponent(item.opengame_url) + "><img src=" + decodeURIComponent(item.icon_url) + "></a></div><div class=\"game_content\"><h1><a href=" + decodeURIComponent(item.opengame_url) + ">" + item.zh_name + "</a></h1><div class=\"star_w\"><p style=\"width:40%\"></p></div><span>人气:" + item.clicks + "</span><div class=\"game_cwz\">" + item.brief + "</div></div><div class=\"game_button\"><a href=" + decodeURIComponent(item.opengame_url) + ">开始游戏</a></div></li>");
			});
		});
	}


猜你喜欢

转载自blog.csdn.net/zxz_1991/article/details/46879439