87,904
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<script type="text/javascript">
function insRow(){
var aa=document.getElementById("myTable").insertRow(myTable.rows.length);
var x=aa.insertCell(0);
var y=aa.insertCell(1);//我增加了一行,这里不应该是0吗,为什么是1
x.innerHTML="当减肥考虑的";
y.innerHTML="山东份额";
//aa.innerHTML="<td>地方考虑的</td><td>222222</td>";//为什么我把上面4行去了,用这个在IE8不行,火狐可以?
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
</table>
<br/>
<input type="button" onclick="insRow()" value="增加一行">
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<table id="a">
<tr></tr>
<tr></tr>
</table>
<input type="button" value="click" id="c" onclick="c()" />
<script>
//add row
function c(){
tbl = document.getElementById("a");
rowsLen = tbl.rows.length;
row = tbl.insertRow(rowsLen);
//create head tag
textNode = document.createTextNode('1111');
cell = row.insertCell(0)//表示列,从0开始,要是加两列,就是row.insertCell(0),row.insertCell(1)
cell.setAttribute("hight","22");
cell.appendChild(textNode);
row.appendChild(cell);
tbl.appendChild(row);
}
</script>
</body>
</html>