js解析json并生成html页面
2012-10-25 16:08:14 来源:WEB开发网issue.js中json格式:
var issueList = [{
date : '201108',
issues : [{
n : '5',
t : '20110817',
d : '../520110817/'
}]
}, {
date : '201109',
issues : [{
n : '2',
t : '20110909',
d : '../220110909/'
}, {
n : '3',
t : '20110916',
d : '../320110916/'
}, {
n : '1',
t : '20110919',
d : '../20110919/'
}, {
n : '1111',
t : '20110921',
d : '../111120110921/'
}, {
n : '11',
t : '20110929',
d : '../日日日20110929/'
}, {
n : '2222',
t : '20110930',
d : '../222220110930/'
}]
}];
analysis.js:
function create_edition(){
var newW = window.open("", "edition" );
newW.document.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"><head>");
newW.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
//newW.document.write("<link href=\"staticpage/css/mulu_m1.css\" type=\"text/css\" rel=\"stylesheet\" rev=\"stylesheet\" media=\"all\"/>");
newW.document.write("<style type=\"text/css\">");
newW.document.write("body{margin:0;padding:0;font-size:12px;font-family:宋体;line-height:180%;}");
newW.document.write("a{text-decoration:none;color:#000;}");
newW.document.write(".div_center {width:987px;margin:auto;padding-top:10px;}");
newW.document.write(".left_c{float:left;width:430px;height:auto;}");
newW.document.write(".ban1 div{ width:406px; height:580px; border:1px solid #932856; padding:5px 0 0 6px; }");
newW.document.write(".right_c1{ float:right; width:530px; padding:100px 0px 0px 20px; }");
newW.document.write(".jj{ height:40px;}h2{ height:50px;}");
newW.document.write("</style>");
newW.document.write("<SCRIPT language=\"Javascript\">");
var issueLists="[";
if(issueList.length >0){
for(var i=0;i<issueList.length;i++){
var issues = issueList[i].issues;
issueLists +="{date: '"+issueList[i].date+"',issues : [";
for(var j=0;j<issues.length;j++){
issueLists +="{n:'"+issues[j].n+"',t:'"+issues[j].t+"',d:'"+issues[j].d+"'}";
if(j != issues.length-1){issueLists +=",";}
if(j == issues.length-1){issueLists += "]}";}
}
if(i != issueList.length-1){issueLists +=",";}
if(i == issueList.length-1){issueLists += "];";}
}
}
newW.document.write("var issueList="+issueLists+";");
//初始 日期参数
newW.document.write("function load_issue(){");
newW.document.write("if(typeof issueList != \"undefined\" && issueList.length >0){");
更多精彩
赞助商链接