html代码:
<div id="news"></div>
txt:
[
{"id":"1", "news":"通知:直面企业社保痛点--为什么企业社保外包成趋势","url":"http://www.baidu.com"},
{"id":"2", "news":"一个好的HR就像一个好的CEO一样","url":"https://www.taobao.com/"},
{"id":"3", "news":"内容运营做不好,和文字编辑没有区别","url":"https://www.taobao.com/"},
{"id":"4","news":"产品生存的根本:核心功能","url":"https://www.taobao.com/"},
{"id":"5","news":"专利申请的误区有哪些","url":"https://www.taobao.com/"},
{"id":"6","news":"管理软件saas企业应用,拨“云”见日","url":"https://www.taobao.com/"},
{"id":"7","news":"梦想之都","url":"https://www.taobao.com/"}
]
js:
<script type="text/javascript">
$.ajax({
type:"POST",
contentType:"application/x-www-form-urlencoded;charset=utf-8",
url:"newsinfo.txt",
dataType:"json",
success:function(data){
var info="<ul>";
//i表示在data中的索引位置,n表示包含的信息的对象
$.each(data,function(i,n){
var str= "<li><a href='"+n["url"]+"'>"+n["news"]+"</a></li>";
info+=str;
});
info+="</ul>";
$('#news').append(info);
}
});
</script>