我正在使用javascript动态生成表行。我可以设置新细胞的高度,但无法对齐细胞内容。
这是我的HTML和Javascript
<table id="myTable">
<tr>
<td height="50" valign="top">Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
<tr>
<td>Row3 cell1</td>
<td>Row3 cell2</td>
</tr>
</table><br>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var table = document.getElementById("myTable");
var row = table.insertRow(1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "NEW CELL1";
cell2.innerHTML = "NEW CELL2";
cell1.height = "50";
cell1.valign = "top";
}
</script>
答案 0 :(得分:2)
你已经写过valign但它实际上是vAlign(A是大写)
cell1.vAlign = "top";