前端js中渲染html案例:
let declareListHtml;
for (let i = 0; i < declareInfo.length; i++) {
let declareId = declareInfo[i].id+""
declareListHtml += "<tr>"
declareListHtml += "<td>"+(i+1)+"</td>"
declareListHtml += "<td>"+declareInfo[i].unit+"</td>"
declareListHtml += "<td>"+declareInfo[i].name+"</td>"
declareListHtml += "<td>"+declareInfo[i].sex+"</td>"
declareListHtml += "<td>"+declareInfo[i].dateOfBirth+"</td>"
declareListHtml += "<td>"+declareInfo[i].joinWorkTime+"</td>"
declareListHtml += "<td>"+declareInfo[i].declareDegree+"</td>"
declareListHtml += "<td>"+declareInfo[i].draduationDate+"</td>"
declareListHtml += "<td>"+declareInfo[i].major+"</td>"
declareListHtml += "<td>"+declareInfo[i].majorIn+"</td>"
declareListHtml += "<td>"+declareInfo[i].jobTitle+"</td>"
declareListHtml += "<td>"+declareInfo[i].workingYears+"</td>"
declareListHtml += "<td>"+declareInfo[i].langueType+"</td>"
declareListHtml += "<td>"+declareInfo[i].score+"</td>"
declareListHtml += "<td>"+declareInfo[i].year+"</td>"
declareListHtml += "<td>"+declareInfo[i].examForm+"</td>"
if (declareInfo[i].declarationForm == "declarationForm"){
declareListHtml +="<td> <button class='common_button' title='申报表' onclick='javaScript:declarationForm(\"" + declareId +"\")' >申报表</button></td>"
}
if (declareInfo[i].businessAutobiography == "businessAutobiography"){
declareListHtml +="<td> <button class='common_button' title='业务自传' onclick=''>业务自传</button></td>"
}
if (declareInfo[i].manuscript == "manuscript"){
declareListHtml +="<td> <button class='common_button' title='评议评价工作底稿' onclick=''>评议评价工作底稿</button></td>"
}
if (declareInfo[i].certificate == "certificate"){
declareListHtml +="<td> <button class='common_button' title='各类证件' onclick='javaScript:certificate(\"" + declareInfo[i].id +"\")'>各类证件</button></td>"
}
if (declareInfo[i].jobPerformance == "jobPerformance"){
declareListHtml +="<td> <button class='common_button' title='工作业绩' onclick='javaScript:jobPerformance(\""+declareInfo[i].id+"\")'>工作业绩</button></td>"
}
if (declareInfo[i].paper == "paper"){
declareListHtml +="<td> <button class='common_button' title='论文论著' onclick='javaScript:paper(\""+declareInfo[i].id+"\")'>论文论著</button></td>"
}
if (declareInfo[i].result == "result"){
declareListHtml +="<td> <button class='common_button' title='论文送审结果' onclick=''>论文送审结果</button></td>"
}
declareListHtml += "<td>"+declareInfo[i].formerYears+"</td>"
declareListHtml += "<td>"+declareInfo[i].remark+"</td>"
declareListHtml += "</tr>"
}
$('#dataSpan').html(declareListHtml)
1、 渲染过程中,要注意单引号与双引号的的使用
2、渲染过程中,在标签中直接渲染点击事件declarationForm并传参id,需要转义id,否则传递过程中会将id(id为长字符串)后三位自动转化为000
declareListHtml +="<td> <button class='common_button' title='申报表' onclick='javaScript:declarationForm(\"" + declareId +"\")' >申报表</button></td>"
οnclick='javaScript:declarationForm(\"" + declareId +"\")'