87,902
社区成员
发帖
与我相关
我的任务
分享
<table border="1" id="table1">
<tr>
<th>姓名</th>
</tr>
<tr>
<td>张三</td>
</tr>
</table>
<input type="button" name="name1" value="插入一列_姓别" onClick="test();"/>
<script language="javascript">
function test()
{
var tr = document.getElementById("table1").rows;
tr[0].insertCell(1).innerHTML="姓别";
}
</script>
<body></body>
<table border="1" id="table1">
<tr>
<th>姓名</th>
</tr>
<tr>
<td>张三</td>
</tr>
</table>
<input type="button" name="name1" value="插入一列_姓别" onClick="test();"/>
<script language="javascript">
function test()
{
var tr = document.getElementById("table1").rows;
//tr[0].insertCell(1).innerHTML="姓别";
var th=document.createElement("th");
th.innerHTML="姓别";
tr[0].appendChild(th);
}
</script>