var data = '{"醉西游":{"icon":"http://m.100week.cn/image","fullurl":"http://m.100week.cn/","type":"角色扮演"},"梦幻家园":{"icon":"http://m.100week.cn/","fullurl":"http://m.100week.cn/","type":"角色扮演"},"传奇世界-仗剑天涯H5":{"icon":"http://m.100week.cn/","fullurl":"http://m.100week.cn/","type":"角色扮演"},"幻城":{"icon":"http://m.100week.cn","fullurl":"http://m.100week.cn/","type":"角色扮演"}}';
我要用这样的数据,做成
<a href="http://m.100week.cn/" class="game_mask">
<h3><img src="http://m.100week.cn/image"/></h3>
<p>醉西游</p>
<div class="ks_btn start_btn">开始游戏</div>
</a>
<a href="http://m.100week.cn/" class="game_mask">
<h3><img src="http://m.100week.cn/"/></h3>
<p>梦幻家园</p>
<div class="ks_btn start_btn">开始游戏</div>
</a>
......
这样,怎么做。在线等!!!
var html = '' var obj = JSON.parse('{"醉西游":{"icon":"http://m.100week.cn/image","fullurl":"http://m.100week.cn/","type":"角色扮演"},"梦幻家园":{"icon":"http://m.100week.cn/","fullurl":"http://m.100week.cn/","type":"角色扮演"},"传奇世界-仗剑天涯H5":{"icon":"http://m.100week.cn/","fullurl":"http://m.100week.cn/","type":"角色扮演"},"幻城":{"icon":"http://m.100week.cn","fullurl":"http://m.100week.cn/","type":"角色扮演"}}') Object.keys(obj).forEach(function(item) { html += `<a href="${obj[item].fullurl}" class="game_mask"> <h3><img src="${obj[item].icon}"/></h3> <p>${item}</p> <div class="ks_btn start_btn">开始游戏</div> </a>` })