给定一个像下面这样的混合使用表,我如何创建一个生成相同表结构的函数。
PS:这是遗留代码,因此不幸的是 taglib 混合语法
要生成的表:
<% if (boolVar) { %>
<img src="../graphics/dot.gif" width="70%" border="0" height="1"><br>
<table id="<%=tableName%>" width="70%" cellpadding="0" cellspacing="0" border="0">
<tr class="titletextrow">
<td class="leftbartextbold" colspan="5" height="14"> TableNameHere</td>
</tr>
<tr>
<td></td>
<td class="label">Column1Name</td>
<td width="60%"></td>
<td class="label">Column2Name</td>
<td></td>
</tr>
<logic:iterate id="someList" name="someForm" property="someList" scope="request" indexId="someIndex">
<SCRIPT> currentRow<%=tableName%> += 1;
</SCRIPT>
<%}%>
<% currentRow += 1; %>
</logic:iterate>
</table>
可能的方法
我正在考虑使用将document.write
参数附加为附加字符串的方法,但由于混合使用的 taglib 语法,它会很混乱。有什么建议么?与此问题直接相关的示例将不胜感激!
<script>
function create() {
var row = parseInt(document.getElementById("row").value);
var col = parseInt(document.getElementById("col").value);
var tablestart = "<table id=myTable border=1>";
var tableend = "</table>";
var trstart = "<tr bgcolor=#ff9966>";
var trend = "</tr>";
var tdstart = "<td>";
var tdend = "</td>";
var data = "data in cell";
var str1 = tablestart + trstart + tdstart + data + tdend + trend + tableend;
document.write(tablestart);
for (var r = 0; r < row; r++) {
document.write(trstart);
for (var c = 0; c < col; c++) {
document.write(tdstart + "Row." + r + " Col." + c + tdend);
}
}
document.write(tableend);
}
</script>