1

我正在使用这种代码:

<table>
    <tr>
    <script>
        document.write("<td>foo</td");
    </script>
    </tr>
</table>

使用 HTML tidy 后,脚本标签被移除到表格之外,因此破坏了页面布局。我知道,这段代码不是最先进的。然而,在不手动重新布线我的页面的情况下,我可以做些什么来整理它?

谢谢

4

1 回答 1

2

您将不得不动态地编写整个表:

<script>
    document.write("<table>");
    document.write("<tr>");
    document.write("<td>foo</td>");
    document.write("</tr>");
    document.write("</table>");
</script>

或者使用更合适的代码,例如:

<table>
    <tr id="Row1"></tr>
</table>
<script>
    document.getElementById("Row1").innerHTML = "<td>foo</td>";
</script>
于 2011-07-20T06:36:46.890 回答