function resultTable(jsonObj){
var titleRow = ['task_id','service_name','thread_num','delay_time','last_time','server_ip','client_ip','test_begin_time','test_end_time','samples',
'throughput','error','90_percent','99_percent','101_to_1000','1001_to_2000','beyond_2000']
var s='<table border="1" style="margin:0 auto; table-layout:fixed" width="100%">'
s+='<tr>'
for(var j=0;j<titleRow.length;j++){//th标题
var rowName=titleRow[j]
s+='<th width="50%" style="word-break:break-all; overflow:hidden;">'+rowName+'</th>'
}
s+='<th width="50%" style="word-break:break-all; overflow:hidden;">IMG</th>'
s+='</tr>'
for(var i=0;i<jsonObj.length;i++){
for(var j=0;j<titleRow.length;j++){
var rowName=titleRow[j]
s+='<td width="50%" style="word-break:break-all; overflow:hidden;">'+jsonObj[i][rowName]+'</td>'
}
s+='<td width="50%"><input type="button" οnclick=showdetail(\''+ jsonObj[i].jstat_img_location +'\',\''+ jsonObj[i].task_id+'\') value="more"></br><div id="'+ jsonObj[i].task_id+'"></div></td>'
s+='</tr>'
}
s+='</table>'
return s
}
s就是表格,在js代表中的调用方式是
document.getElementById("divResult_content").innerHTML= resultTable(jsonObj)
html中的div标签是
<div id="divResult_content"></div>